diff options
| author | Andreas Kapp Lindquist <andkaplin05@gmail.com> | 2025-10-28 11:41:36 +0100 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-29 13:49:57 +0100 |
| commit | f1cc32749fdbeecc76d1f4f28766caf815782d32 (patch) | |
| tree | d8b1c270becc36167a5c2dcf1d92d8b9ebf81325 /test/benchmark.sh | |
| parent | 6b37376a66ea5caf283fb2476206f6e4f99dd28e (diff) | |
| download | sorter-f1cc32749fdbeecc76d1f4f28766caf815782d32.tar.gz sorter-f1cc32749fdbeecc76d1f4f28766caf815782d32.zip | |
test(benchmark.sh): Made benchmark loop over sortingalgorithms
Diffstat (limited to '')
| -rwxr-xr-x | test/benchmark.sh | 35 |
1 files changed, 20 insertions, 15 deletions
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 |