From f1cc32749fdbeecc76d1f4f28766caf815782d32 Mon Sep 17 00:00:00 2001 From: Andreas Kapp Lindquist Date: Tue, 28 Oct 2025 11:41:36 +0100 Subject: test(benchmark.sh): Made benchmark loop over sortingalgorithms --- test/benchmark.sh | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/benchmark.sh b/test/benchmark.sh index 2f0d90b..d7c69f0 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -3,30 +3,35 @@ DATA_DIR="data" SRC_DIR="../src" SORTER="$SRC_DIR/sorter" +ALGORITHMS=("isort" "qsort") 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) + for ALGORITHM in "${ALGORITHMS[@]}"; do - # 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]}') + echo "Benchmarking $FILE_NAME using $ALGORITHM ..." - # Remove prefix and suffix - # type_size_n.tsv - TYPE="${FILE_NAME%%_*}" # before first _ - rest="${FILE_NAME#*_}" # after first _ - TEST_SIZE="${rest%%_*}" # before next _ + # Run the command and capture timing + TIME_OUTPUT=$({ time $SORTER -a "$ALGORITHM" "$TEST_FILE" >/dev/null; } 2>&1) - # Add entry to JSON string - OUTPUT_STRING="$OUTPUT_STRING -$TYPE,$TEST_SIZE,$REAL,$USER,$SYS" + # 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 +$ALGORITHM"_"$TYPE,$TEST_SIZE,$REAL,$USER,$SYS" + done done # Write to file -- cgit v1.2.3-70-g09d2