aboutsummaryrefslogtreecommitdiff
path: root/old/benchmark/bench.c
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/bench.c
parent7812684339d03f6993882358b0045c1bc2d5032c (diff)
downloadnissy-core-c04a283a7ab97903683f5f7268068aef69f5bddf.tar.gz
nissy-core-c04a283a7ab97903683f5f7268068aef69f5bddf.zip
Added benchmark; removed old folder
Diffstat (limited to 'old/benchmark/bench.c')
-rw-r--r--old/benchmark/bench.c83
1 files changed, 0 insertions, 83 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}

Generated with cgit - Back to sebastiano.tronto.net