summaryrefslogtreecommitdiffhomepage
path: root/bench/measure-jobs.sh
blob: af43a1c09423664aa1c01a354597559b2ecd3269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/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