diff options
| author | Andreas Kapp Lindquist <andkaplin05@gmail.com> | 2025-10-28 14:21:03 +0100 |
|---|---|---|
| committer | mithe24 <mithe24@student.sdu.dk> | 2025-10-29 13:49:57 +0100 |
| commit | 6746b29daa5b26b53d0c3fa3da26a6d54dcc5a73 (patch) | |
| tree | f8d0861b11cff6ad265085f283b1bad057a4cf08 /test | |
| parent | e119499fc68085b5c915091de2432465c24724e0 (diff) | |
| download | sorter-6746b29daa5b26b53d0c3fa3da26a6d54dcc5a73.tar.gz sorter-6746b29daa5b26b53d0c3fa3da26a6d54dcc5a73.zip | |
test(benchmark.sh): replaced time with perf stat
Diffstat (limited to 'test')
| -rwxr-xr-x | test/benchmark.sh | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/test/benchmark.sh b/test/benchmark.sh index d7c69f0..b8bc156 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -5,7 +5,7 @@ SRC_DIR="../src" SORTER="$SRC_DIR/sorter" ALGORITHMS=("isort" "qsort") -OUTPUT_STRING="type,size,real,user,sys" +OUTPUT_STRING="type,size,time" for TEST_FILE in "$DATA_DIR"/*; do FILE_NAME=$(basename "$TEST_FILE") @@ -14,13 +14,8 @@ for TEST_FILE in "$DATA_DIR"/*; do echo "Benchmarking $FILE_NAME using $ALGORITHM ..." - # Run the command and capture timing - TIME_OUTPUT=$({ time $SORTER -a "$ALGORITHM" "$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]}') + time=$(perf stat -e task-clock $SORTER -a "$ALGORITHM" "$TEST_FILE" >/dev/null 2> perf_out.txt) + elapsed=$(grep "seconds time elapsed" perf_out.txt | awk '{print $1}') # Remove prefix and suffix # type_size_n.tsv @@ -28,11 +23,10 @@ for TEST_FILE in "$DATA_DIR"/*; do 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" +$ALGORITHM"_"$TYPE,$TEST_SIZE,$elapsed" done done - +rm perf_out.txt # Write to file echo "$OUTPUT_STRING" > benchmark_results.csv |