diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-13 22:28:49 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-13 22:28:49 +0200 |
| commit | c04a283a7ab97903683f5f7268068aef69f5bddf (patch) | |
| tree | 9809c4a71c2ad1a5123371c32c34f03b1b703ecf /benchmark | |
| parent | 7812684339d03f6993882358b0045c1bc2d5032c (diff) | |
| download | nissy-core-c04a283a7ab97903683f5f7268068aef69f5bddf.tar.gz nissy-core-c04a283a7ab97903683f5f7268068aef69f5bddf.zip | |
Added benchmark; removed old folder
Diffstat (limited to 'benchmark')
| -rw-r--r-- | benchmark/00_gendata_h48/gendata_h48_benchmark.c | 42 | ||||
| -rw-r--r-- | benchmark/benchmark.h | 39 | ||||
| -rwxr-xr-x | benchmark/benchmark.sh | 27 |
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 | |||
| 9 | char *buf; | ||
| 10 | |||
| 11 | void 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 | |||
| 28 | int 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 | |||
| 7 | double | ||
| 8 | time_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 | |||
| 3 | re="${RUN:-$@}" | ||
| 4 | |||
| 5 | CC="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 | |||
| 11 | BIN="benchmark/run" | ||
| 12 | RES="benchmark/results" | ||
| 13 | CUBEOBJ="cube.o" | ||
| 14 | d="$(date +'%Y-%m-%d-%H-%M-%S')" | ||
| 15 | |||
| 16 | mkdir -p "$RES" | ||
| 17 | |||
| 18 | for 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" | ||
| 25 | done | ||
| 26 | |||
| 27 | rm -rf $BIN $CUBEOBJ | ||
