Created
February 15, 2025 10:54
-
-
Save jason810496/11b208fb964e0c490a6cd82f7d1882f7 to your computer and use it in GitHub Desktop.
Simple script for benchmarking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ "$#" -eq 0 ]; then | |
| echo "Usage: $0 <command>" | |
| exit 1 | |
| fi | |
| TOTAL_TIME=0 | |
| NUM_RUNS=5 | |
| echo -e "Running: $@ ($NUM_RUNS times)\n" | |
| OUTPUT="" | |
| for i in $(seq 1 $NUM_RUNS); do | |
| START_TIME=$(date +%s.%N) | |
| "$@" | |
| END_TIME=$(date +%s.%N) | |
| ELAPSED_TIME=$(awk "BEGIN {print $END_TIME - $START_TIME}") | |
| TOTAL_TIME=$(awk "BEGIN {print $TOTAL_TIME + $ELAPSED_TIME}") | |
| OUTPUT+="Run $i: ${ELAPSED_TIME} seconds\n" | |
| done | |
| AVERAGE_TIME=$(awk "BEGIN {print $TOTAL_TIME / $NUM_RUNS}") | |
| OUTPUT+="Average time: ${AVERAGE_TIME} seconds" | |
| echo -e "$OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment