From 2bb91575a5a5d033e97c2bb329f18c83eaaaa991 Mon Sep 17 00:00:00 2001 From: Andreas Kapp Lindquist Date: Thu, 23 Oct 2025 17:56:12 +0200 Subject: test(benchmark.sh): moved to test and added support for different types --- benchmark.sh | 31 ------------------------------- test/benchmark.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 31 deletions(-) delete mode 100755 benchmark.sh create mode 100755 test/benchmark.sh diff --git a/benchmark.sh b/benchmark.sh deleted file mode 100755 index 3811fc2..0000000 --- a/benchmark.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -DATA_DIR="data" -SRC_DIR="src" -SORTER="$SRC_DIR/sorter" - -OUTPUT_STRING="size,real,user,sys" - -for TEST_FILE in "$DATA_DIR"/*; do - FILE_NAME=$(basename "$TEST_FILE") - echo "Benchmarking $FILE_NAME ..." - - # Run the command and capture timing - TIME_OUTPUT=$({ time $SORTER "$TEST_FILE" >/dev/null; } 2>&1) - - # Extract real, user, sys in seconds - REAL=$(echo "$TIME_OUTPUT" | awk '/real/ {split($2,a,"m"); split(a[2],b,"s"); print a[1]*60 + b[1]}') - USER=$(echo "$TIME_OUTPUT" | awk '/user/ {split($2,a,"m"); split(a[2],b,"s"); print a[1]*60 + b[1]}') - SYS=$(echo "$TIME_OUTPUT" | awk '/sys/ {split($2,a,"m"); split(a[2],b,"s"); print a[1]*60 + b[1]}') - - # Remove prefix and suffix - TEST_SIZE=${FILE_NAME#random_} # removes 'random_' - TEST_SIZE=${TEST_SIZE%_run*} # removes '_run...' part - - # Add entry to JSON string - OUTPUT_STRING="$OUTPUT_STRING -$TEST_SIZE,$REAL,$USER,$SYS" -done - -# Write to file -echo "$OUTPUT_STRING" > benchmark_results.csv diff --git a/test/benchmark.sh b/test/benchmark.sh new file mode 100755 index 0000000..2f0d90b --- /dev/null +++ b/test/benchmark.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +DATA_DIR="data" +SRC_DIR="../src" +SORTER="$SRC_DIR/sorter" + +OUTPUT_STRING="type,size,real,user,sys" + +for TEST_FILE in "$DATA_DIR"/*; do + FILE_NAME=$(basename "$TEST_FILE") + echo "Benchmarking $FILE_NAME ..." + + # Run the command and capture timing + TIME_OUTPUT=$({ time $SORTER "$TEST_FILE" >/dev/null; } 2>&1) + + # Extract real, user, sys in seconds + REAL=$(echo "$TIME_OUTPUT" | awk '/real/ {split($2,a,"m"); split(a[2],b,"s"); print a[1]*60 + b[1]}') + USER=$(echo "$TIME_OUTPUT" | awk '/user/ {split($2,a,"m"); split(a[2],b,"s"); print a[1]*60 + b[1]}') + SYS=$(echo "$TIME_OUTPUT" | awk '/sys/ {split($2,a,"m"); split(a[2],b,"s"); print a[1]*60 + b[1]}') + + # Remove prefix and suffix + # type_size_n.tsv + TYPE="${FILE_NAME%%_*}" # before first _ + rest="${FILE_NAME#*_}" # after first _ + TEST_SIZE="${rest%%_*}" # before next _ + + # Add entry to JSON string + OUTPUT_STRING="$OUTPUT_STRING +$TYPE,$TEST_SIZE,$REAL,$USER,$SYS" +done + +# Write to file +echo "$OUTPUT_STRING" > benchmark_results.csv -- cgit v1.2.3-70-g09d2