blob: da388a549079bdfc1a37c8f847a00332a4cd8015 (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/sh
# Start-up cost: wall time for one start of a shell.
#
# sh bench/startup.sh ./zash [shell[=label] ...]
#
# run.sh measures the CPU a script's body costs; this measures what a
# process costs before it runs anything, and it has to be wall time: the
# expensive part is waiting for the runtime to come up, which costs
# almost no CPU and so never appears in run.sh's table.
#
# Two columns, because a `#!` line pays for both: `-c :` is the bare
# start, and `script` starts the shell on a one-line file, which is what
# the kernel does for `./script`.
#
# BENCH_N starts per shell (default 100) after five warm-up starts, so a
# shell that reads its own files off disk is not paying for the first
# read. The clock is tests/tools/now.c, built by `make bench` as
# build/zos-tools/now; point BENCH_NOW at another one if need be.
here=$(cd "$(dirname "$0")" && pwd)
now=${BENCH_NOW:-$here/../build/zos-tools/now}
n=${BENCH_N:-100}
[ -x "$now" ] || { echo "startup: $now is not built; run make bench" >&2; exit 2; }
shells=
labels=
for a in "$@"; do
p=${a%%=*}
case $a in *=*) l=${a#*=} ;; *) l= ;; esac
[ -n "$l" ] || l=${p##*/}
[ "$p" = /bin/sh ] && [ "$(uname -s)" = OS/390 ] && l='z/OS sh'
shells=${shells:+$shells }$p
labels=${labels:+$labels|}$l
done
# One shell means "this one, plus whatever else this machine has".
if [ $# -eq 1 ]; then
found=
for s in dash bash ksh zsh oksh; do
if command -v "$s" >/dev/null 2>&1; then
shells=${shells:+$shells }$s
labels=${labels:+$labels|}${s##*/}
found=$s
fi
done
[ -n "$found" ] || { shells=$shells" /bin/sh"; labels=${labels:+$labels|}sh; }
fi
script=startup-bench.$$
printf ':\n' >"$script"
trap 'rm -f "$script"' EXIT
# Milliseconds for one start of the command given. Integer arithmetic
# and printf, so it needs nothing beyond POSIX sh: awk on z/OS chokes on
# the quoting that a one-line program built from variables produces.
per_start() {
i=0
while [ $i -lt 5 ]; do "$@" >/dev/null 2>&1; i=$((i + 1)); done
t0=$("$now")
i=0
while [ $i -lt "$n" ]; do "$@" >/dev/null 2>&1; i=$((i + 1)); done
t1=$("$now")
d=$((t1 - t0))
[ $d -lt 0 ] && d=$((d + 1000000000)) # the clock wrapped its window
us=$((d / n))
printf '%d.%02d' $((us / 1000)) $(((us % 1000) / 10))
}
printf '%-12s%12s%12s\n' shell '-c :' script
rest=$labels
while [ -n "$rest" ]; do
l=${rest%%|*}
if [ "$l" = "$rest" ]; then rest=; else rest=${rest#*|}; fi
s=${shells%% *}
if [ "$s" = "$shells" ]; then shells=; else shells=${shells#* }; fi
# A name that is not there fails instantly and would look like the
# fastest shell in the table.
command -v "$s" >/dev/null 2>&1 || {
printf '%-12s%12s%12s\n' "$l" n/a n/a
continue
}
printf '%-12s%12s%12s\n' "$l" "$(per_start "$s" -c :)" \
"$(per_start "$s" "$script")"
done
|