aboutsummaryrefslogtreecommitdiff
path: root/old/benchmark
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-06-13 22:28:49 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-06-13 22:28:49 +0200
commitc04a283a7ab97903683f5f7268068aef69f5bddf (patch)
tree9809c4a71c2ad1a5123371c32c34f03b1b703ecf /old/benchmark
parent7812684339d03f6993882358b0045c1bc2d5032c (diff)
downloadnissy-core-c04a283a7ab97903683f5f7268068aef69f5bddf.tar.gz
nissy-core-c04a283a7ab97903683f5f7268068aef69f5bddf.zip
Added benchmark; removed old folder
Diffstat (limited to 'old/benchmark')
-rw-r--r--old/benchmark/bench.c83
-rwxr-xr-xold/benchmark/bench.sh21
-rw-r--r--old/benchmark/cube-bench.c147
3 files changed, 0 insertions, 251 deletions
diff --git a/old/benchmark/bench.c b/old/benchmark/bench.c
deleted file mode 100644
index 2c3358f..0000000
--- a/old/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
14double
15bench(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
51int 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/old/benchmark/bench.sh b/old/benchmark/bench.sh
deleted file mode 100755
index cc31c1e..0000000
--- a/old/benchmark/bench.sh
+++ /dev/null
@@ -1,21 +0,0 @@
1#!/bin/sh
2
3CC="cc -std=c99 -O3 -D$CUBETYPE"
4if [ "$CUBETYPE" = "CUBE_AVX2" ]; then
5 CC="$CC -mavx2"
6fi
7
8BENCHBIN="benchmark/run"
9BENCHDIR="benchmark/results"
10CUBEOBJ="cube.o"
11
12$CC -D_POSIX_C_SOURCE=199309L -o $BENCHBIN benchmark/bench.c $CUBEOBJ || exit 1
13
14d="$(date +'%Y-%m-%d-%H-%M-%S')"
15mkdir -p "$BENCHDIR"
16$BENCHBIN | tee "$BENCHDIR/results-$d.txt" "$BENCHDIR/results.txt"
17
18echo ""
19echo "Results saved to $BENCHDIR/results.txt"
20
21rm -rf $BENCHBIN $CUBEOBJ
diff --git a/old/benchmark/cube-bench.c b/old/benchmark/cube-bench.c
deleted file mode 100644
index 26d12a4..0000000
--- a/old/benchmark/cube-bench.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/******************************************************************************
2Section: benchmarks
3
4Here you can find some simple functions that can be used to benchmark the
5rest of the code.
6******************************************************************************/
7
8#define RANDOMCUBES 157
9
10static void
11setup_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
19cube_t
20run_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
55cube_t
56run_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
121cube_t
122run_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
135cube_t
136run_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}

Generated with cgit - Back to sebastiano.tronto.net