diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-10 17:07:42 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-11-10 19:55:55 +0100 |
| commit | 067ba55add258ab03db328234168af66c4ad87c3 (patch) | |
| tree | f4861907117c420eed3f9c9aa967bf9f2c6a1f7e /benchmark | |
| parent | af1399f223e3857a3d2690337e84430cdbeff16a (diff) | |
| download | nissy-core-067ba55add258ab03db328234168af66c4ad87c3.tar.gz nissy-core-067ba55add258ab03db328234168af66c4ad87c3.zip | |
Towards a definitve API
Diffstat (limited to 'benchmark')
| -rw-r--r-- | benchmark/bench.c | 83 | ||||
| -rwxr-xr-x | benchmark/bench.sh | 21 | ||||
| -rw-r--r-- | benchmark/cube-bench.c | 147 |
3 files changed, 0 insertions, 251 deletions
diff --git a/benchmark/bench.c b/benchmark/bench.c deleted file mode 100644 index 2c3358f..0000000 --- a/benchmark/bench.c +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <time.h> | ||
| 6 | |||
| 7 | #include "../cube.h" | ||
| 8 | |||
| 9 | #define MOVES 100000000 | ||
| 10 | #define TRANS 100000000 | ||
| 11 | #define COMPOSE 100000000 | ||
| 12 | #define INVERSE 100000000 | ||
| 13 | |||
| 14 | double | ||
| 15 | bench(cube_t (*run)(int64_t), int64_t n, char *name) | ||
| 16 | { | ||
| 17 | char str[1000]; | ||
| 18 | cube_t cube; | ||
| 19 | struct timespec start, end; | ||
| 20 | double tdiff, tdsec, tdnano; | ||
| 21 | |||
| 22 | printf("\n"); | ||
| 23 | fflush(stdout); | ||
| 24 | |||
| 25 | if (run == NULL) { | ||
| 26 | printf("> %s: nothing to run!\n", name); | ||
| 27 | fflush(stdout); | ||
| 28 | return -1.0; | ||
| 29 | } | ||
| 30 | |||
| 31 | printf("> %s: running benchmark...\n", name); | ||
| 32 | fflush(stdout); | ||
| 33 | clock_gettime(CLOCK_MONOTONIC, &start); | ||
| 34 | |||
| 35 | cube = run(n); | ||
| 36 | writecube("H48", cube, str); | ||
| 37 | str[3] = 0; | ||
| 38 | printf("> %s: resulting cube, first piece: %s\n", name, str); | ||
| 39 | fflush(stdout); | ||
| 40 | |||
| 41 | clock_gettime(CLOCK_MONOTONIC, &end); | ||
| 42 | tdsec = end.tv_sec - start.tv_sec; | ||
| 43 | tdnano = end.tv_nsec - start.tv_nsec; | ||
| 44 | tdiff = tdsec + 1e-9 * tdnano; | ||
| 45 | printf("> %s: %.4fs\n", name, tdiff); | ||
| 46 | fflush(stdout); | ||
| 47 | |||
| 48 | return tdiff; | ||
| 49 | } | ||
| 50 | |||
| 51 | int main() { | ||
| 52 | double tmoves, ttrans, tcompose, tinverse; | ||
| 53 | |||
| 54 | printf( | ||
| 55 | "Benchmarks settings:\n" | ||
| 56 | "MOVES:\t%d\nTRANS:\t%d\nCOMPOSE:\t%d\nINVERSE:\t%d\n", | ||
| 57 | MOVES, TRANS, COMPOSE, INVERSE | ||
| 58 | ); | ||
| 59 | fflush(stdout); | ||
| 60 | |||
| 61 | srand(time(NULL)); | ||
| 62 | |||
| 63 | tmoves = bench(run_moves, MOVES, "moves"); | ||
| 64 | ttrans = bench(run_trans, TRANS, "trans"); | ||
| 65 | tcompose = bench(run_compose, COMPOSE, "compose"); | ||
| 66 | tinverse = bench(run_inverse, INVERSE, "inverse"); | ||
| 67 | |||
| 68 | printf( | ||
| 69 | "\nBenchmark summary:\n" | ||
| 70 | "moves: %d moves in %.4fs (%.4f MTPS)\n" | ||
| 71 | "trans: %d transformations in %.4fs (%.4f MTPS)\n" | ||
| 72 | "compose: %d compositions in %.4fs (%.4f MCPS)\n" | ||
| 73 | "inverse: %d inverses in %.4fs (%.4f MIPS)\n" | ||
| 74 | "Total time: %.4f\n", | ||
| 75 | MOVES, tmoves, MOVES / (1e6 * tmoves), | ||
| 76 | TRANS, ttrans, TRANS / (1e6 * ttrans), | ||
| 77 | COMPOSE, tcompose, COMPOSE / (1e6 * tcompose), | ||
| 78 | INVERSE, tinverse, INVERSE / (1e6 * tinverse), | ||
| 79 | tmoves + ttrans + tcompose + tinverse | ||
| 80 | ); | ||
| 81 | |||
| 82 | return 0; | ||
| 83 | } | ||
diff --git a/benchmark/bench.sh b/benchmark/bench.sh deleted file mode 100755 index cc31c1e..0000000 --- a/benchmark/bench.sh +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | CC="cc -std=c99 -O3 -D$CUBETYPE" | ||
| 4 | if [ "$CUBETYPE" = "CUBE_AVX2" ]; then | ||
| 5 | CC="$CC -mavx2" | ||
| 6 | fi | ||
| 7 | |||
| 8 | BENCHBIN="benchmark/run" | ||
| 9 | BENCHDIR="benchmark/results" | ||
| 10 | CUBEOBJ="cube.o" | ||
| 11 | |||
| 12 | $CC -D_POSIX_C_SOURCE=199309L -o $BENCHBIN benchmark/bench.c $CUBEOBJ || exit 1 | ||
| 13 | |||
| 14 | d="$(date +'%Y-%m-%d-%H-%M-%S')" | ||
| 15 | mkdir -p "$BENCHDIR" | ||
| 16 | $BENCHBIN | tee "$BENCHDIR/results-$d.txt" "$BENCHDIR/results.txt" | ||
| 17 | |||
| 18 | echo "" | ||
| 19 | echo "Results saved to $BENCHDIR/results.txt" | ||
| 20 | |||
| 21 | rm -rf $BENCHBIN $CUBEOBJ | ||
diff --git a/benchmark/cube-bench.c b/benchmark/cube-bench.c deleted file mode 100644 index 26d12a4..0000000 --- a/benchmark/cube-bench.c +++ /dev/null | |||
| @@ -1,147 +0,0 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | Section: benchmarks | ||
| 3 | |||
| 4 | Here you can find some simple functions that can be used to benchmark the | ||
| 5 | rest of the code. | ||
| 6 | ******************************************************************************/ | ||
| 7 | |||
| 8 | #define RANDOMCUBES 157 | ||
| 9 | |||
| 10 | static void | ||
| 11 | setup_randomcubes(cube_fast_t *cubes) | ||
| 12 | { | ||
| 13 | int i; | ||
| 14 | |||
| 15 | for (i = 0; i < RANDOMCUBES; i++) | ||
| 16 | cubes[i] = run_moves(i*4); | ||
| 17 | } | ||
| 18 | |||
| 19 | cube_t | ||
| 20 | run_moves(int64_t n) | ||
| 21 | { | ||
| 22 | cube_fast_t fast; | ||
| 23 | int64_t m, i; | ||
| 24 | |||
| 25 | fast = solvedcube(); | ||
| 26 | m = n / 18; | ||
| 27 | |||
| 28 | for (i = 0; i < m; i++) { | ||
| 29 | fast = _move_U(fast); | ||
| 30 | fast = _move_U2(fast); | ||
| 31 | fast = _move_U3(fast); | ||
| 32 | fast = _move_D(fast); | ||
| 33 | fast = _move_D2(fast); | ||
| 34 | fast = _move_D3(fast); | ||
| 35 | fast = _move_R(fast); | ||
| 36 | fast = _move_R2(fast); | ||
| 37 | fast = _move_R3(fast); | ||
| 38 | fast = _move_L(fast); | ||
| 39 | fast = _move_L2(fast); | ||
| 40 | fast = _move_L3(fast); | ||
| 41 | fast = _move_F(fast); | ||
| 42 | fast = _move_F2(fast); | ||
| 43 | fast = _move_F3(fast); | ||
| 44 | fast = _move_B(fast); | ||
| 45 | fast = _move_B2(fast); | ||
| 46 | fast = _move_B3(fast); | ||
| 47 | } | ||
| 48 | |||
| 49 | for (i = m * 18; i < n; i++) | ||
| 50 | fast = _move_F(fast); | ||
| 51 | |||
| 52 | return fast; | ||
| 53 | } | ||
| 54 | |||
| 55 | cube_t | ||
| 56 | run_trans(int64_t n) | ||
| 57 | { | ||
| 58 | cube_fast_t fast; | ||
| 59 | int64_t m, i; | ||
| 60 | |||
| 61 | fast = run_moves(33); | ||
| 62 | m = n / 18; | ||
| 63 | |||
| 64 | for (i = 0; i < m; i++) { | ||
| 65 | fast = _trans_UFr(fast); | ||
| 66 | fast = _trans_ULr(fast); | ||
| 67 | fast = _trans_UBr(fast); | ||
| 68 | fast = _trans_URr(fast); | ||
| 69 | fast = _trans_DFr(fast); | ||
| 70 | fast = _trans_DLr(fast); | ||
| 71 | fast = _trans_DBr(fast); | ||
| 72 | fast = _trans_DRr(fast); | ||
| 73 | fast = _trans_RUr(fast); | ||
| 74 | fast = _trans_RFr(fast); | ||
| 75 | fast = _trans_RDr(fast); | ||
| 76 | fast = _trans_RBr(fast); | ||
| 77 | fast = _trans_LUr(fast); | ||
| 78 | fast = _trans_LFr(fast); | ||
| 79 | fast = _trans_LDr(fast); | ||
| 80 | fast = _trans_LBr(fast); | ||
| 81 | fast = _trans_FUr(fast); | ||
| 82 | fast = _trans_FRr(fast); | ||
| 83 | fast = _trans_FDr(fast); | ||
| 84 | fast = _trans_FLr(fast); | ||
| 85 | fast = _trans_BUr(fast); | ||
| 86 | fast = _trans_BRr(fast); | ||
| 87 | fast = _trans_BDr(fast); | ||
| 88 | fast = _trans_BLr(fast); | ||
| 89 | fast = _trans_UFm(fast); | ||
| 90 | fast = _trans_ULm(fast); | ||
| 91 | fast = _trans_UBm(fast); | ||
| 92 | fast = _trans_URm(fast); | ||
| 93 | fast = _trans_DFm(fast); | ||
| 94 | fast = _trans_DLm(fast); | ||
| 95 | fast = _trans_DBm(fast); | ||
| 96 | fast = _trans_DRm(fast); | ||
| 97 | fast = _trans_RUm(fast); | ||
| 98 | fast = _trans_RFm(fast); | ||
| 99 | fast = _trans_RDm(fast); | ||
| 100 | fast = _trans_RBm(fast); | ||
| 101 | fast = _trans_LUm(fast); | ||
| 102 | fast = _trans_LFm(fast); | ||
| 103 | fast = _trans_LDm(fast); | ||
| 104 | fast = _trans_LBm(fast); | ||
| 105 | fast = _trans_FUm(fast); | ||
| 106 | fast = _trans_FRm(fast); | ||
| 107 | fast = _trans_FDm(fast); | ||
| 108 | fast = _trans_FLm(fast); | ||
| 109 | fast = _trans_BUm(fast); | ||
| 110 | fast = _trans_BRm(fast); | ||
| 111 | fast = _trans_BDm(fast); | ||
| 112 | fast = _trans_BLm(fast); | ||
| 113 | } | ||
| 114 | |||
| 115 | for (i = m * 18; i < n; i++) | ||
| 116 | fast = _trans_FRm(fast); | ||
| 117 | |||
| 118 | return fast; | ||
| 119 | } | ||
| 120 | |||
| 121 | cube_t | ||
| 122 | run_compose(int64_t n) | ||
| 123 | { | ||
| 124 | cube_fast_t fast, cubes[RANDOMCUBES]; | ||
| 125 | int64_t i; | ||
| 126 | |||
| 127 | setup_randomcubes(cubes); | ||
| 128 | |||
| 129 | for (i = 0; i < n; i++) | ||
| 130 | fast = compose_fast(fast, cubes[i % RANDOMCUBES]); | ||
| 131 | |||
| 132 | return fast; | ||
| 133 | } | ||
| 134 | |||
| 135 | cube_t | ||
| 136 | run_inverse(int64_t n) | ||
| 137 | { | ||
| 138 | cube_fast_t fast, cubes[RANDOMCUBES]; | ||
| 139 | int64_t i; | ||
| 140 | |||
| 141 | setup_randomcubes(cubes); | ||
| 142 | |||
| 143 | for (i = 0; i < n; i++) | ||
| 144 | fast = inverse_fast(cubes[i % RANDOMCUBES]); | ||
| 145 | |||
| 146 | return fast; | ||
| 147 | } | ||
