# bench The benchmark scripts, and what the numbers cost on z/OS. Each script is also a test: `run.sh` compares every shell's output with the reference shell's, so a wrong answer fails instead of merely being timed. ## Running On Linux, `make bench`. On z/OS (ASCII build), from the source directory: ```sh export PATH=/bin:/usr/bin TMPDIR=$HOME/tmp _BPXK_AUTOCVT=ON sh bench/run.sh "$(pwd)/zash" /bin/sh bash zsh oksh ``` Three things about that line are not optional: - **Every shell is an absolute path.** `run.sh` changes to a work directory before running anything, so a relative `./zash` prints `n/a` in every row. - **`_BPXK_AUTOCVT=ON`.** The scripts are tagged ISO8859-1. Without it, /bin/sh and the other shells cannot read them and fail with `FSUM7332 syntax error: got ), expecting Newline`. zash is not affected: it converts by tag itself. - **`TMPDIR` on a writable filesystem.** That is where the work directory goes. A full run takes about a minute and is best run detached (`nohup ... > bench.txt 2>&1 #include #include #include #include #include int main(int argc, char **argv) { long mb = argc > 1 ? atol(argv[1]) : 0; int n = argc > 2 ? atoi(argv[2]) : 100; char *p = NULL; if (mb > 0) { p = malloc((size_t)mb * 1024 * 1024); if (!p) { printf("malloc failed\n"); return 1; } memset(p, 'x', (size_t)mb * 1024 * 1024); } struct tms a, b; times(&a); for (int i = 0; i < n; i++) { pid_t c = fork(); if (c == 0) _exit(0); int st; waitpid(c, &st, 0); } times(&b); clock_t t = (b.tms_utime - a.tms_utime) + (b.tms_stime - a.tms_stime) + (b.tms_cutime - a.tms_cutime) + (b.tms_cstime - a.tms_cstime); printf(" %4ld MB: %6.2f s (%5.2f ms per fork)", mb, (double)t / 100.0, (double)t / 100.0 * 1000.0 / n); if (p) printf(" [p[0]=%c]", p[0]); printf("\n"); return 0; } ``` ```sh ibm-clang -O2 -m64 -o fk_64 fk3.c && ibm-clang -O2 -m32 -o fk_32 fk3.c for m in 0 8 64; do ./fk_64 $m 100; ./fk_32 $m 100; done ``` Start-up cost is measured by starting a program that does nothing, so that nothing but the run-time matters: ```sh echo 'int main(void) { return 0; }' > tiny.c ibm-clang -O2 -m64 -o t64 tiny.c && ibm-clang -O2 -m32 -o t32 tiny.c time sh -c 'i=0; while [ $i -lt 100 ]; do ./t64; i=$((i+1)); done' time sh -c 'i=0; while [ $i -lt 100 ]; do ./t32; i=$((i+1)); done' ``` Two traps in getting this right, both of which produced wrong answers here first: - **Check the build, not the flag.** `-m31` is rejected; `-m32` is the spelling that works, and `file` prints `amode=31` for the result. `ibm-clang -print-targets` lists `systemz32` as a registered target. - **Make sure the probe measures what you think.** `return p ? 0 : 0;` lets the compiler delete the allocation, and the "8 MB" row then reads the same as "0 MB". Touch the memory after the loop. ## LE run-time options: no measurable effect The obvious suspect for a 4 ms `fork()` and a 28 ms start is LE's own sizing — `HEAP64`, `HEAPPOOLS64`, `STACK64`. It is not. | `_CEE_RUNOPTS` | fork | start | | --- | --- | --- | | defaults | 4.4 ms | 29.4 ms | | `HEAPPOOLS64(OFF)` | 4.2 ms | 29.4 ms | | `HEAP64(256M,256M,KEEP,16M,16M,KEEP,4M,4M,FREE),HEAPPOOLS64(OFF)` | 4.4 ms | — | | `STACK64(1M,1M,4M)` | — | 29.3 ms | | `STACK64(1M,1M,64M)` | 4.2 ms | 29.7 ms | | all of the small ones together | — | 29.4 ms | Everything lands inside the run-to-run spread. So there is nothing to tune and nothing worth building into the program with a `CELQUOPT` module: the cost is not in the sizes LE is asked for. `HEAP64` numbers are in megabytes and must carry an `M` (`HEAP64(256K,...)` is rejected). To see the effective options and the storage actually used, in case a future LE release behaves differently: ```sh _CEE_RUNOPTS='RPTOPTS(ON),RPTSTG(ON)' ./zash -c : 2>rpt.txt ``` The report lists each option, its value, and where it was set — installation default, `CELQUOPT`, or the `_CEE_RUNOPTS` override. Both reports go to the message file, stderr by default. `_CEE_RUNOPTS` is inherited, so any LE child of the process prints its own report; `-c :` keeps that to one. ## Start-up is not in these numbers `run.sh` takes CPU time, so the ~28 ms of wall time a 64-bit program spends starting is invisible to every row. That is why `subshell` and `zz-fgsub` can read 0.00 for zash while `zash -c :` takes 30 ms of wall time. Both statements are true, and the CPU table is the wrong place to look for start-up cost. 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. Compare it with `time`, not with `make bench`. ## Address mode and the 31-bit build zash is a 31-bit (AMODE 31) XPLINK program, which is what the z/OS Makefile targets build. It used to be 64-bit; the costs above are what that choice cost, and they were the whole of the remaining z/OS gap. The same sources build at either width with the same compiler: ```sh ibm-clang ... -O2 -m32 -fzos-le-char-mode=ascii -o zash $(COMMON) src/sys_zos.c ``` (`-m32` is 32-bit XPLINK, `-m32n` is 32-bit non-XPLINK, `-m64` is 64-bit XPLINK. `-m31` does not exist and is rejected.) Measured against `/bin/sh`, CPU seconds, ASCII build, same box: | benchmark | zash `-m64` | zash `-m32` | z/OS sh | | --- | --- | --- | --- | | `jobs` (200 `( : ) &`) | 0.90 | 0.07 | 0.12 | | `zz-bgsub` (200 `( : ) &`) | 0.86 | 0.08 | 0.12 | | `zz-bgcd` (200 `( cd / ) &`) | 0.85 | 0.08 | 0.12 | | `zz-fgcd` (200 `( cd / )` fg) | 0.84 | 0.08 | 0.05 | | `zz-fgsub` (200 `( : )` fg) | 0.00 | 0.00 | 0.04 | | `zz-bgtrue` (200 `/bin/true &`) | 0.06 | 0.05 | 0.10 | | `zz-bgsh` (200 `/bin/sh -c : &`) | 0.06 | 0.05 | 0.14 | The rows that fork improve by a factor of ten and stop being losses. Nothing else moves: `report` 0.18 → 0.16, `deploy` 0.15 → 0.14, `spawn` 0.47 → 0.45, `cmdsub` 0.04 → 0.04, `strings` 0.28 → 0.25, `printf` 1.17 → 1.15. Every row is the same or slightly better, because a smaller address space costs nothing. Two things had to be settled before 31-bit could ship, and both are: 1. **The catalog search.** It used to need `zos_csi.s`, an `AMODE 64` routine that switched modes with `SAM31`/`SAM64` around IGGCSI00 and passed a `__malloc31` block. At 31-bit the C code calls IGGCSI00 directly, with `fetch()` and `#pragma linkage(..., OS_UPSTACK)`, and the assembler is gone. Two traps cost a day between them: under `-m32` plain `OS` means `OS_NOSTACK` and the call takes a program check (use `OS_UPSTACK`), and the name given to `fetch()` must be an ordinary literal, because `__fetch_a` converts it and EBCDIC bytes get converted twice. 2. **Address space.** A 31-bit shell is limited to storage below 2 GB. Ample for a shell, not for `x=$( zash.amblist # note the leading blank grep -nE 'AMODE|RMODE|ENTRY POINT' zash.amblist ``` `make zos-amblist` does this for `./zash`. At 31-bit there is no assembler CSECT left to check, so the listing should show one member and `AMODE 31` throughout. **What storage does the program actually use?** This is the input to fork cost, and the reason a big shell would fork more slowly than a small one: ```sh _CEE_RUNOPTS='RPTSTG(ON)' ./zash -c : 2>rpt.txt _CEE_RUNOPTS='RPTOPTS(ON)' ./zash -c : 2>opts.txt ``` RPTSTG reports heap and stack use per enclave; RPTOPTS reports every run-time option, its value, and where it was set. Both go to the message file, stderr by default. **Where is the shell spending CPU?** `dbx` works on z/OS and is the target of `make zos-debug` and `make zos-dbx`. Note that the costs above are not CPU — nearly all of the 28 ms is a wait — so a profile taken inside zash will not show them. That is why the probes here are separate programs rather than shell built-ins. **What did the compiler emit?** `ibm-clang -S` gives assembly, and `-fsave-optimization-record` (or `-Rpass=`) gives clang's remarks about what was and was not optimised. ## Reading the two tables `n/a` means the shell lacks the feature the benchmark uses. `differs` means it computed something else, and the run says so. `port bug` marks the third-party oksh port's own breakage (`echo hi | cat` prints garbage there), not anything zash did. Rows that create processes move by a few hundredths between runs, and the fork-heavy ones move more, so treat a 0.01–0.02 difference as noise and re-run before believing it.