commit 4a16da26dacdb37b9ef8d3d11e10ecb94b0cf396
parent 3c9efb490ccbe1b0d7768d77fcdcac012c00e8c6
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Wed, 3 Jul 2024 15:05:10 +0200
renamed benchmarks to tools
Diffstat:
7 files changed, 116 insertions(+), 111 deletions(-)
diff --git a/Makefile b/Makefile
@@ -17,8 +17,8 @@ clean:
test: debugcube.o
CUBETYPE=${CUBETYPE} TEST=${TEST} ./test/test.sh
-benchmark: cube.o
- CUBETYPE=${CUBETYPE} ./benchmark/benchmark.sh
+tool: cube.o
+ CUBETYPE=${CUBETYPE} ./tools/run_tool.sh
shell: cube.o
mkdir -p tables
@@ -28,4 +28,4 @@ debugshell: debugcube.o
mkdir -p tables
${CC} ${DBGFLAGS} -o run debugcube.o shell.c
-.PHONY: all clean test benchmark shell debugshell
+.PHONY: all clean test tool shell debugshell
diff --git a/benchmark/00_gendata_h48/gendata_h48_benchmark.c b/benchmark/00_gendata_h48/gendata_h48_benchmark.c
@@ -1,42 +0,0 @@
-#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
@@ -1,39 +0,0 @@
-#include <stdbool.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-
-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
@@ -1,27 +0,0 @@
-#!/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
diff --git a/tools/benchmark_gendata_h48/benchmark_gendata_h48.c b/tools/benchmark_gendata_h48/benchmark_gendata_h48.c
@@ -0,0 +1,47 @@
+#include "../timerun.h"
+#include "../../src/cube.h"
+
+#define MAXDEPTH 10
+#define HVALUE 2
+#define OPTIONS "2;10"
+#define LONGOPTIONS "h = 2, max depth = 10"
+
+#define COCSEPSIZE 1119792
+#define ETABLESIZE(h) (((3393 * 495 * 70) >> 1) << (size_t)(h))
+
+char *buf;
+
+void run(void) {
+ uint32_t *h48info;
+ 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);
+ h48info = (uint32_t *)buf + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4;
+ for (i = 0; i < MAXDEPTH+1; i++)
+ printf("%d:\t%" PRIu32 "\n", i, h48info[i+1]);
+ }
+}
+
+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);
+
+ timerun(run, "benchmark gendata_h48 " LONGOPTIONS);
+
+ free(buf);
+
+ return 0;
+}
diff --git a/tools/run_tool.sh b/tools/run_tool.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+if [ -z "$TOOL" ]; then
+ echo "No tool selected (TOOL variable must be set)"
+ exit 1
+fi
+
+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="tools/run"
+CUBEOBJ="cube.o"
+d="$(date +'%Y-%m-%d-%H-%M-%S')"
+
+for t in tools/*; do
+ if [ ! -d "$t" ] || [ -z "$(echo "$t" | grep "$TOOL")" ]; then
+ continue
+ fi
+ $CC -o $BIN $t/*.c $CUBEOBJ || exit 1;
+ $BIN
+ break
+done
+
+rm -rf $BIN $CUBEOBJ
diff --git a/tools/timerun.h b/tools/timerun.h
@@ -0,0 +1,39 @@
+#include <stdbool.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+double
+timerun(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("Running tool: %s\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;
+}