dotfiles/scripts/.local/bin/benchmark
Marty Oehme a110acbdbf
[script] Add simple benchmark script
`benchmark` can be invoked with an executable file after it. It will
output the running time in milliseconds. Depends on gnu date being
installed on the system.
2020-05-08 11:39:06 +02:00

19 lines
503 B
Bash
Executable file

#!/usr/bin/env sh
# Benchmarking script using gnu date
# can be used to output running time of script in milliseconds
# usage: benchmark scripttorun
#
# Note: script itself uses roughly 1 millisecond (on my system), so subtract that
# from https://unix.stackexchange.com/a/334152
START=$(date +%s.%N)
# do something #######################
"$@" 1>/dev/null 2>/dev/null
#######################################
END=$(date +%s.%N)
DIFF=$(echo "scale=3; (${END} - ${START})*1000/1" | bc)
echo "${DIFF}"