dotfiles

personal dotfiles
git clone anongit@rnpnr.xyz:dotfiles.git
Log | Files | Refs | Feed | Submodules

avgtime (532B)


      1 #!/bin/sh
      2 
      3 # calculates the average time from executing cmd n times (128 default)
      4 
      5 usage()
      6 {
      7 	echo "usage: ${0##*/} [-n samples] cmd [arg ...]"
      8 }
      9 
     10 N=128
     11 if [ "$1" = "-n" ]; then
     12 	N="${2}"; shift 2
     13 fi
     14 [ $# -gt 0 ] || usage
     15 
     16 for _ in $(seq "${N}"); do
     17 	time -p "$@" 2>&1 >/dev/null
     18 done | awk '
     19 /real/ { real = real + $2; nr++ }
     20 /user/ { user = user + $2; nu++ }
     21 /sys/  { sys = sys + $2; ns++ }
     22 END {
     23 	if (nr > 0) printf("real %f\n", real / nr)
     24 	if (nu > 0) printf("user %f\n", user / nu)
     25 	if (ns > 0) printf("sys %f\n", sys / ns)
     26 }'