Created
September 2, 2019 09:31
-
-
Save juniorprincewang/6eb92e1aee20a3527dba58e2e6f939ef to your computer and use it in GitHub Desktop.
Benchmarking programs in Linux SHELL
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
#!/bin/bash | |
avg_time() { | |
# usage: avg_time n command ... | |
# | |
n=$1; shift | |
(($# > 0)) || return | |
for((i = 0; i < n; i++)); do | |
{ time -p "$@" &>/dev/null; } 2>&1 | |
done | awk ' | |
/real/ {real = real + $2; nr++ } | |
/user/ {user = user + $2; nu++ } | |
/sys/ {sys = sys + $2; ns++ } | |
END { | |
if (nr>0) printf("real %f\n", real/nr); | |
if (nu>0) printf("user %f\n", user/nu); | |
if (ns>0) printf("sys %f\n", sys/ns); | |
} | |
' | |
} | |
avg_time 10 time /home/max/NVIDIA_CUDA-9.1_Samples/0_Simple/vectorAdd/vectorAdd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment