#!/bin/sh # Throwaway: what does a background job cost, by shape of job? # sh bench/measure-jobs.sh '( : )' '/bin/true' "/bin/sh -c :" cpu() { times > bench.t1 cpu=$(awk 'NR == 2 { t = 0 for (i = 1; i <= NF; i++) { v = $i if (v ~ /m/) { split(v, a, "m") t += a[1] * 60 if (a[2] != "") { sub(/s$/, "", a[2]); t += a[2] } } else if (v ~ /s$/) { sub(/s$/, "", v); t += v } } printf "%.2f", t }' bench.t1) } for pat in "$@"; do cpu before=$cpu i=0 while [ $i -lt 200 ]; do eval "$pat &" i=$((i + 1)) done wait cpu after=$cpu printf '%-22s %s s\n' "$pat" \ "$(awk -v a="$after" -v b="$before" 'BEGIN { printf "%.2f", a - b }')" done rm -f bench.t1