From c04a283a7ab97903683f5f7268068aef69f5bddf Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 13 Jun 2024 22:28:49 +0200 Subject: Added benchmark; removed old folder --- benchmark/00_gendata_h48/gendata_h48_benchmark.c | 42 ++++++++++++++++++++++++ benchmark/benchmark.h | 39 ++++++++++++++++++++++ benchmark/benchmark.sh | 27 +++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 benchmark/00_gendata_h48/gendata_h48_benchmark.c create mode 100644 benchmark/benchmark.h create mode 100755 benchmark/benchmark.sh (limited to 'benchmark') 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 @@ +#include "../benchmark.h" +#include "../../src/cube.h" + +#define MAXDEPTH 10 +#define HVALUE 2 +#define OPTIONS "2;10" +#define LONGOPTIONS "h = 2, max depth = 10" + +char *buf; + +void run(void) { + uint32_t *buf32; + int i; + int64_t s; + + s = nissy_gendata("H48", OPTIONS, buf); + + if (s == -1) { + printf("Error generating table\n"); + } else { + printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); + buf32 = (uint32_t *)&buf[s-sizeof(uint32_t)*(MAXDEPTH+1)]; + for (i = 0; i <= MAXDEPTH; i++) + printf("%d:\t%" PRId32 "\n", i, buf32[i]); + } +} + +int main() { + int64_t size; + + size = nissy_datasize("H48", OPTIONS); + if (size == -1) { + printf("gendata_h48 benchmark: error in datasize\n"); + return 1; + } + + buf = malloc(size); + + time_benchmark(run, "gendata_h48 " LONGOPTIONS); + + return 0; +} 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 @@ +#include +#include +#include +#include +#include + +double +time_benchmark(void (*run)(void), char *name) +{ + struct timespec start, end; + double tdiff, tdsec, tdnano; + + printf("\n"); + fflush(stdout); + + if (run == NULL) { + printf("> %s: nothing to run!\n", name); + fflush(stdout); + return -1.0; + } + + printf("Benchmark: %s\n\n", name); + printf("==========\n"); + fflush(stdout); + + clock_gettime(CLOCK_MONOTONIC, &start); + run(); + clock_gettime(CLOCK_MONOTONIC, &end); + + tdsec = end.tv_sec - start.tv_sec; + tdnano = end.tv_nsec - start.tv_nsec; + tdiff = tdsec + 1e-9 * tdnano; + + printf("==========\n"); + printf("\nTotal time: %.4fs\n", tdiff); + fflush(stdout); + + return tdiff; +} 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 @@ +#!/bin/sh + +re="${RUN:-$@}" + +CC="cc -std=c99 -pedantic -Wall -Wextra \ + -Wno-unused-parameter -Wno-unused-function -O3 -D$CUBETYPE \ + -D_POSIX_C_SOURCE=199309L" + +[ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2" + +BIN="benchmark/run" +RES="benchmark/results" +CUBEOBJ="cube.o" +d="$(date +'%Y-%m-%d-%H-%M-%S')" + +mkdir -p "$RES" + +for t in benchmark/*; do + if [ -n "$re" ] && [ -z "$(echo "$t" | grep "$re")" ]; then + continue + fi + if [ ! -d "$t" ] || [ "$t" = "benchmark/results" ]; then continue; fi + $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; + $BIN | tee "$RES/results-$d.txt" "$RES/results-last.txt" +done + +rm -rf $BIN $CUBEOBJ -- cgit v1.3