dotfiles/scripts/.local/bin/benchmark

19 lines
503 B
Text
Raw Permalink Normal View History

#!/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}"