Plan 9 from Bell Labs’s /usr/web/sources/contrib/anothy/bin/rc/timeavg

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

# average multiple 'time' runs. do something like this:
# {for (i in `{seq 1 10}) {time cmd1 ; time cmd2 }>/dev/null} |[2] timeavg
# and you'll get a report like:
# cmd1 (10 runs): 0.00	0.00	0.07
# cmd2 (10 runs): 0.00	0.00	0.04

# BUG: differentiates based on command, without args, so you can't
# time the difference between 'foo -a' and 'foo -b' (they're both foo).

sed -n 's/([0-9]+\.[0-9]+)[usr]/\1/gp' | awk ' {
		usert[$4] += $1
		systemt[$4] += $2
		realt[$4] += $3
		runs[$4] +=1
	}

	END{ for (i in runs) {
		r = runs[i]
		printf("%s (%d runs): ", i, r)
		printf("%.2f	%.2f	%.2f\n", usert[i]/r, systemt[i]/r, realt[i]/r)
	}
	}
'

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].