diff options
Diffstat (limited to 'test/benchmark.sh')
| -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 |