Created
January 28, 2021 10:44
-
-
Save steinybot/ba680a7a9306cdb876700fd1937635e0 to your computer and use it in GitHub Desktop.
Benchmark script
This file contains 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
#!/usr/bin/env bash | |
set -euo pipefail | |
REPEATS=100 | |
OUTPUT_FILE='results.csv' | |
run_tests() { | |
echo "Benchmarking ${COMMAND[@]}" | |
[ -f "${OUTPUT_FILE}" ] || echo "command,exit status of command,elapsed real time (wall clock) in seconds,user time (seconds),system (kernel) time in seconds" > "${OUTPUT_FILE}" | |
escaped_command='"' | |
for i in "${!COMMAND[@]}"; do | |
((i != 0)) && escaped_command="$escaped_command " | |
escaped_command="$escaped_command${COMMAND[i]//\"/\"\"}" | |
done | |
escaped_command="$escaped_command\"" | |
for ((i = 1; i <= REPEATS; i++)); do | |
printf '\x1b[1000D' | |
printf '%0.s ' {1..1000} | |
printf '\x1b[1000D' | |
printf 'running test %i out of %i' "${i}" "${REPEATS}" | |
#/usr/bin/time -f "%E,%U,%S" -o ${OUTPUT_FILE} -a ${COMMAND[*]} > /dev/null 2>&1 | |
gtime -f "${escaped_command},%x,%e,%U,%S" -o ${OUTPUT_FILE} -a "${COMMAND[@]}" >/dev/null 2>&1 | |
# Clear the HDD cache (I hope?) | |
#sync && echo 3 > /proc/sys/vm/drop_caches | |
done | |
} | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-o | --output-file) | |
OUTPUT_FILE="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-n | --repeats) | |
REPEATS="$2" | |
shift # past argument | |
shift # past value | |
;; | |
*) # unknown option | |
break | |
;; | |
esac | |
done | |
COMMAND=("$@") | |
run_tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment