aboutsummaryrefslogtreecommitdiff
path: root/test/benchmark.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test/benchmark.sh')
-rwxr-xr-xtest/benchmark.sh35
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