[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.
This commit is contained in:
Marty Oehme 2020-05-08 11:39:06 +02:00
parent 3e2d17aa5f
commit a110acbdbf
No known key found for this signature in database
GPG Key ID: 0CCB0526EFB9611A
1 changed files with 18 additions and 0 deletions

18
scripts/.local/bin/benchmark Executable file
View File

@ -0,0 +1,18 @@
#!/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}"