dotfiles

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

Commit: 32011a3f5cc2ff1ebc74f3e3eb849dc262c323ea
Parent: ac5f999aec07961b39c0c3061882c1082ced0821
Author: Randy Palamar
Date:   Sat, 28 Oct 2023 17:39:32 -0600

add bin/avgtime script

Diffstat:
Abin/avgtime | 27+++++++++++++++++++++++++++
1 file changed, 27 insertions(+), 0 deletions(-)

diff --git a/bin/avgtime b/bin/avgtime @@ -0,0 +1,27 @@ +#!/bin/sh + +# calculates the average time from executing cmd n times (128 default) + +N=128 + +usage() +{ + echo "usage: ${0##*/} [-n samples] cmd [arg ...]" +} + +if [ "$1" = "-n" ]; then + shift; N="${1}"; shift +fi +[ $# -gt 0 ] || usage + +for _ in $(seq "${N}"); do + time -p "$@" 2>&1 >/dev/null +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) +}'