aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/00_gendata_h48/gendata_h48_benchmark.c42
-rw-r--r--benchmark/benchmark.h39
-rwxr-xr-xbenchmark/benchmark.sh27
3 files changed, 108 insertions, 0 deletions
diff --git a/benchmark/00_gendata_h48/gendata_h48_benchmark.c b/benchmark/00_gendata_h48/gendata_h48_benchmark.c
new file mode 100644
index 0000000..1dc7c57
--- /dev/null
+++ b/benchmark/00_gendata_h48/gendata_h48_benchmark.c
@@ -0,0 +1,42 @@
1#include "../benchmark.h"
2#include "../../src/cube.h"
3
4#define MAXDEPTH 10
5#define HVALUE 2
6#define OPTIONS "2;10"
7#define LONGOPTIONS "h = 2, max depth = 10"
8
9char *buf;
10
11void run(void) {
12 uint32_t *buf32;
13 int i;
14 int64_t s;
15
16 s = nissy_gendata("H48", OPTIONS, buf);
17
18 if (s == -1) {
19 printf("Error generating table\n");
20 } else {
21 printf("Succesfully generated %" PRId64 " bytes. Table:\n", s);
22 buf32 = (uint32_t *)&buf[s-sizeof(uint32_t)*(MAXDEPTH+1)];
23 for (i = 0; i <= MAXDEPTH; i++)
24 printf("%d:\t%" PRId32 "\n", i, buf32[i]);
25 }
26}
27
28int main() {
29 int64_t size;
30
31 size = nissy_datasize("H48", OPTIONS);
32 if (size == -1) {
33 printf("gendata_h48 benchmark: error in datasize\n");
34 return 1;
35 }
36
37 buf = malloc(size);
38
39 time_benchmark(run, "gendata_h48 " LONGOPTIONS);
40
41 return 0;
42}
diff --git a/benchmark/benchmark.h b/benchmark/benchmark.h
new file mode 100644
index 0000000..e9361a8
--- /dev/null
+++ b/benchmark/benchmark.h
@@ -0,0 +1,39 @@
1#include <stdbool.h>
2#include <inttypes.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <time.h>
6
7double
8time_benchmark(void (*run)(void), char *name)
9{
10 struct timespec start, end;
11 double tdiff, tdsec, tdnano;
12
13 printf("\n");
14 fflush(stdout);
15
16 if (run == NULL) {
17 printf("> %s: nothing to run!\n", name);
18 fflush(stdout);
19 return -1.0;
20 }
21
22 printf("Benchmark: %s\n\n", name);
23 printf("==========\n");
24 fflush(stdout);
25
26 clock_gettime(CLOCK_MONOTONIC, &start);
27 run();
28 clock_gettime(CLOCK_MONOTONIC, &end);
29
30 tdsec = end.tv_sec - start.tv_sec;
31 tdnano = end.tv_nsec - start.tv_nsec;
32 tdiff = tdsec + 1e-9 * tdnano;
33
34 printf("==========\n");
35 printf("\nTotal time: %.4fs\n", tdiff);
36 fflush(stdout);
37
38 return tdiff;
39}
diff --git a/benchmark/benchmark.sh b/benchmark/benchmark.sh
new file mode 100755
index 0000000..6de280c
--- /dev/null
+++ b/benchmark/benchmark.sh
@@ -0,0 +1,27 @@
1#!/bin/sh
2
3re="${RUN:-$@}"
4
5CC="cc -std=c99 -pedantic -Wall -Wextra \
6 -Wno-unused-parameter -Wno-unused-function -O3 -D$CUBETYPE \
7 -D_POSIX_C_SOURCE=199309L"
8
9[ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2"
10
11BIN="benchmark/run"
12RES="benchmark/results"
13CUBEOBJ="cube.o"
14d="$(date +'%Y-%m-%d-%H-%M-%S')"
15
16mkdir -p "$RES"
17
18for t in benchmark/*; do
19 if [ -n "$re" ] && [ -z "$(echo "$t" | grep "$re")" ]; then
20 continue
21 fi
22 if [ ! -d "$t" ] || [ "$t" = "benchmark/results" ]; then continue; fi
23 $CC -o $BIN $t/*.c $CUBEOBJ || exit 1;
24 $BIN | tee "$RES/results-$d.txt" "$RES/results-last.txt"
25done
26
27rm -rf $BIN $CUBEOBJ

Generated with cgit - Back to sebastiano.tronto.net