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 --- old/benchmark/bench.c | 83 ------------------------- old/benchmark/bench.sh | 21 ------- old/benchmark/cube-bench.c | 147 --------------------------------------------- 3 files changed, 251 deletions(-) delete mode 100644 old/benchmark/bench.c delete mode 100755 old/benchmark/bench.sh delete mode 100644 old/benchmark/cube-bench.c (limited to 'old/benchmark') 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 @@ -#include -#include -#include -#include -#include - -#include "../cube.h" - -#define MOVES 100000000 -#define TRANS 100000000 -#define COMPOSE 100000000 -#define INVERSE 100000000 - -double -bench(cube_t (*run)(int64_t), int64_t n, char *name) -{ - char str[1000]; - cube_t cube; - 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("> %s: running benchmark...\n", name); - fflush(stdout); - clock_gettime(CLOCK_MONOTONIC, &start); - - cube = run(n); - writecube("H48", cube, str); - str[3] = 0; - printf("> %s: resulting cube, first piece: %s\n", name, str); - fflush(stdout); - - 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("> %s: %.4fs\n", name, tdiff); - fflush(stdout); - - return tdiff; -} - -int main() { - double tmoves, ttrans, tcompose, tinverse; - - printf( - "Benchmarks settings:\n" - "MOVES:\t%d\nTRANS:\t%d\nCOMPOSE:\t%d\nINVERSE:\t%d\n", - MOVES, TRANS, COMPOSE, INVERSE - ); - fflush(stdout); - - srand(time(NULL)); - - tmoves = bench(run_moves, MOVES, "moves"); - ttrans = bench(run_trans, TRANS, "trans"); - tcompose = bench(run_compose, COMPOSE, "compose"); - tinverse = bench(run_inverse, INVERSE, "inverse"); - - printf( - "\nBenchmark summary:\n" - "moves: %d moves in %.4fs (%.4f MTPS)\n" - "trans: %d transformations in %.4fs (%.4f MTPS)\n" - "compose: %d compositions in %.4fs (%.4f MCPS)\n" - "inverse: %d inverses in %.4fs (%.4f MIPS)\n" - "Total time: %.4f\n", - MOVES, tmoves, MOVES / (1e6 * tmoves), - TRANS, ttrans, TRANS / (1e6 * ttrans), - COMPOSE, tcompose, COMPOSE / (1e6 * tcompose), - INVERSE, tinverse, INVERSE / (1e6 * tinverse), - tmoves + ttrans + tcompose + tinverse - ); - - return 0; -} diff --git a/old/benchmark/bench.sh b/old/benchmark/bench.sh deleted file mode 100755 index cc31c1e..0000000 --- a/old/benchmark/bench.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -CC="cc -std=c99 -O3 -D$CUBETYPE" -if [ "$CUBETYPE" = "CUBE_AVX2" ]; then - CC="$CC -mavx2" -fi - -BENCHBIN="benchmark/run" -BENCHDIR="benchmark/results" -CUBEOBJ="cube.o" - -$CC -D_POSIX_C_SOURCE=199309L -o $BENCHBIN benchmark/bench.c $CUBEOBJ || exit 1 - -d="$(date +'%Y-%m-%d-%H-%M-%S')" -mkdir -p "$BENCHDIR" -$BENCHBIN | tee "$BENCHDIR/results-$d.txt" "$BENCHDIR/results.txt" - -echo "" -echo "Results saved to $BENCHDIR/results.txt" - -rm -rf $BENCHBIN $CUBEOBJ diff --git a/old/benchmark/cube-bench.c b/old/benchmark/cube-bench.c deleted file mode 100644 index 26d12a4..0000000 --- a/old/benchmark/cube-bench.c +++ /dev/null @@ -1,147 +0,0 @@ -/****************************************************************************** -Section: benchmarks - -Here you can find some simple functions that can be used to benchmark the -rest of the code. -******************************************************************************/ - -#define RANDOMCUBES 157 - -static void -setup_randomcubes(cube_fast_t *cubes) -{ - int i; - - for (i = 0; i < RANDOMCUBES; i++) - cubes[i] = run_moves(i*4); -} - -cube_t -run_moves(int64_t n) -{ - cube_fast_t fast; - int64_t m, i; - - fast = solvedcube(); - m = n / 18; - - for (i = 0; i < m; i++) { - fast = _move_U(fast); - fast = _move_U2(fast); - fast = _move_U3(fast); - fast = _move_D(fast); - fast = _move_D2(fast); - fast = _move_D3(fast); - fast = _move_R(fast); - fast = _move_R2(fast); - fast = _move_R3(fast); - fast = _move_L(fast); - fast = _move_L2(fast); - fast = _move_L3(fast); - fast = _move_F(fast); - fast = _move_F2(fast); - fast = _move_F3(fast); - fast = _move_B(fast); - fast = _move_B2(fast); - fast = _move_B3(fast); - } - - for (i = m * 18; i < n; i++) - fast = _move_F(fast); - - return fast; -} - -cube_t -run_trans(int64_t n) -{ - cube_fast_t fast; - int64_t m, i; - - fast = run_moves(33); - m = n / 18; - - for (i = 0; i < m; i++) { - fast = _trans_UFr(fast); - fast = _trans_ULr(fast); - fast = _trans_UBr(fast); - fast = _trans_URr(fast); - fast = _trans_DFr(fast); - fast = _trans_DLr(fast); - fast = _trans_DBr(fast); - fast = _trans_DRr(fast); - fast = _trans_RUr(fast); - fast = _trans_RFr(fast); - fast = _trans_RDr(fast); - fast = _trans_RBr(fast); - fast = _trans_LUr(fast); - fast = _trans_LFr(fast); - fast = _trans_LDr(fast); - fast = _trans_LBr(fast); - fast = _trans_FUr(fast); - fast = _trans_FRr(fast); - fast = _trans_FDr(fast); - fast = _trans_FLr(fast); - fast = _trans_BUr(fast); - fast = _trans_BRr(fast); - fast = _trans_BDr(fast); - fast = _trans_BLr(fast); - fast = _trans_UFm(fast); - fast = _trans_ULm(fast); - fast = _trans_UBm(fast); - fast = _trans_URm(fast); - fast = _trans_DFm(fast); - fast = _trans_DLm(fast); - fast = _trans_DBm(fast); - fast = _trans_DRm(fast); - fast = _trans_RUm(fast); - fast = _trans_RFm(fast); - fast = _trans_RDm(fast); - fast = _trans_RBm(fast); - fast = _trans_LUm(fast); - fast = _trans_LFm(fast); - fast = _trans_LDm(fast); - fast = _trans_LBm(fast); - fast = _trans_FUm(fast); - fast = _trans_FRm(fast); - fast = _trans_FDm(fast); - fast = _trans_FLm(fast); - fast = _trans_BUm(fast); - fast = _trans_BRm(fast); - fast = _trans_BDm(fast); - fast = _trans_BLm(fast); - } - - for (i = m * 18; i < n; i++) - fast = _trans_FRm(fast); - - return fast; -} - -cube_t -run_compose(int64_t n) -{ - cube_fast_t fast, cubes[RANDOMCUBES]; - int64_t i; - - setup_randomcubes(cubes); - - for (i = 0; i < n; i++) - fast = compose_fast(fast, cubes[i % RANDOMCUBES]); - - return fast; -} - -cube_t -run_inverse(int64_t n) -{ - cube_fast_t fast, cubes[RANDOMCUBES]; - int64_t i; - - setup_randomcubes(cubes); - - for (i = 0; i < n; i++) - fast = inverse_fast(cubes[i % RANDOMCUBES]); - - return fast; -} -- cgit v1.3