diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:25:47 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:25:47 -0600 |
| commit | ab003863f9a3eaf6099d560af64022b7bd7c2f2a (patch) | |
| tree | a5551d9e19c117281807834b2a7cfce27740eb70 | |
| parent | 1109062b7c8418026fc5461f81cd98632f5e5658 (diff) | |
| download | zash-bench/startup-rounds.tar.gz | |
bench: make the start-up number a minimum of interleaved roundsbench/startup-rounds
startup.sh ran BENCH_N starts once, and on the shared z/OS machine the
same binary measured anywhere between 5 and 14 ms depending on the hour.
Now each cell is the fastest of BENCH_R rounds (default 5) of BENCH_N
starts, and a row's two columns are measured one after the other inside
each round, so `-c :` and `script` see the same load instead of one
following five rounds of the other. A minimum is the right summary
because contention only adds time.
Measured that way on cbt today, zash is 1.34 ms for `-c :` and 1.36 ms
for a script, and the z/OS sh 2.16 and 2.18 — the same two numbers
bench/README.md already claimed from a quieter machine, which is the
point: the method now reproduces them.
Also records the rule the ksh88 constraint implies: where zash and the
z/OS sh disagree, zash keeps the better behaviour unless a ksh88 script
could observe it, and the one such case — a failed redirection,
assignment or read being 2 rather than 1 — is accepted because POSIX
does not pin it and the shells disagree among themselves.
| -rw-r--r-- | DESIGN.md | 7 | ||||
| -rw-r--r-- | bench/README.md | 9 | ||||
| -rwxr-xr-x | bench/startup.sh | 39 |
3 files changed, 46 insertions, 9 deletions
@@ -841,6 +841,13 @@ Rules: fields, and `command eval` still exiting on an error. `bench/README.md` classifies every difference the two shells show on the `tests/posix` corpus, and none of them is a zash bug. +- The rule behind those two bullets: where zash and the z/OS `/bin/sh` + disagree, zash keeps the better behaviour as long as a script written + for IBM's ksh88 cannot tell the difference. The one case where it can + is the status of a failed redirection, assignment or `read`: 2 here + and 1 there. That stays, because POSIX does not pin the value and the + shells disagree among themselves (bash says 1, dash and FreeBSD sh + say 2), so no portable script can test for it. - An expansion error in a command the shell prepares for a child (a pipeline stage, `&`, `$( )`) is reported on the shell's stderr, not on the stderr that command would have had. diff --git a/bench/README.md b/bench/README.md index bb290a7..9621ba3 100644 --- a/bench/README.md +++ b/bench/README.md @@ -264,6 +264,15 @@ process is mostly waiting for the runtime to come up, which costs almost no CPU. `startup.sh` measures it, by the wall clock, one start per `shell -c :` and one per `shell script`. +A cell is the fastest of `BENCH_R` rounds (default 5) of `BENCH_N` +starts (default 100), and the two columns of a row are measured one +after the other inside each round, so they see the same load. A minimum +is the right summary because contention only ever adds time; the +comment at the top of the script says why `awk` is not used. On a shared +z/OS machine the absolute numbers still move with whatever else the LPAR +is running: read a run's rows against each other, not against a table +from a different day. + It matters for anything that starts zash often: a script with a `#!` line, `zash -c`, a spawned subshell. It does not matter for a long interactive session. diff --git a/bench/startup.sh b/bench/startup.sh index da388a5..c3dbe57 100755 --- a/bench/startup.sh +++ b/bench/startup.sh @@ -14,11 +14,15 @@ # # 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 +# read. BENCH_R rounds of that are run and the fastest is reported +# (default 5), because on a shared machine the noise only ever adds +# time: a minimum is what one start costs when nothing else is running. +# 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} +r=${BENCH_R:-5} [ -x "$now" ] || { echo "startup: $now is not built; run make bench" >&2; exit 2; } shells= @@ -48,10 +52,11 @@ 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() { +# Microseconds for one start of the command given, as the fastest of $r +# rounds. 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. +one_round() { i=0 while [ $i -lt 5 ]; do "$@" >/dev/null 2>&1; i=$((i + 1)); done t0=$("$now") @@ -60,8 +65,24 @@ per_start() { 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 '%d' $((d / n)) +} + +# Fastest of $r rounds for both columns, measured in step so that the two +# numbers in a row share the machine's load. Prints "a b", in ms. +row() { + best_a= + best_b= + k=0 + while [ $k -lt "$r" ]; do + u=$(one_round "$1" -c :) + if [ -z "$best_a" ] || [ "$u" -lt "$best_a" ]; then best_a=$u; fi + u=$(one_round "$1" "$script") + if [ -z "$best_b" ] || [ "$u" -lt "$best_b" ]; then best_b=$u; fi + k=$((k + 1)) + done + printf '%d.%02d %d.%02d' $((best_a / 1000)) $(((best_a % 1000) / 10)) \ + $((best_b / 1000)) $(((best_b % 1000) / 10)) } printf '%-12s%12s%12s\n' shell '-c :' script @@ -77,6 +98,6 @@ while [ -n "$rest" ]; do 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")" + pair=$(row "$s") + printf '%-12s%12s%12s\n' "$l" "${pair% *}" "${pair#* }" done |
