aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kapp Lindquist <andkaplin05@gmail.com>2025-10-22 20:04:15 +0200
committermithe24 <mithe24@student.sdu.dk>2025-10-29 13:49:57 +0100
commit9539d225f69f8a956b6d77985a7553f2d9bf9c7b (patch)
tree28858ca1d3b8eb122cd9cb2274b3db3413a56c26
parente0d2d485a3f344edf267df643c9b08b6fa77c899 (diff)
downloadsorter-9539d225f69f8a956b6d77985a7553f2d9bf9c7b.tar.gz
sorter-9539d225f69f8a956b6d77985a7553f2d9bf9c7b.zip
feat(benchmark.sh): script for testing speed of sorter, and saving results to csv
Diffstat (limited to '')
-rwxr-xr-xbenchmark.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/benchmark.sh b/benchmark.sh
new file mode 100755
index 0000000..3811fc2
--- /dev/null
+++ b/benchmark.sh
@@ -0,0 +1,31 @@
+#!/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