summaryrefslogtreecommitdiffhomepage
path: root/web/content/_index.md
blob: e24eebf8b28d83b524b273d65ef335526213a124 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
title: zash
description: A small, fast POSIX shell for z/OS UNIX System Services, in the Almquist (ash) tradition.
---

## Why another shell

The z/OS `/bin/sh` is dated, and the usual alternatives are bash and zsh.
Those are comfortable interactively but slow as scripting shells, large, and
encourage scripts that run nowhere else. On z/OS that cost is real: CPU time is
billed, and every `fork()` copies an address space.

<ol class="specs">
  <li>
    <span class="n">01</span>
    <h3>spawn(), not fork()</h3>
    <p>Children come from <code>spawn()</code>, so <code>_BPX_SHAREAS</code>
    can keep them in the same address space. Builtins cost no process at all,
    even in a pipeline or a command substitution.</p>
  </li>
  <li>
    <span class="n">02</span>
    <h3>sh scripts, not a dialect</h3>
    <p>Scripts written for zash run under the existing <code>/bin/sh</code>,
    dash, FreeBSD sh and bash. zash is the successor to IBM's KornShell-line
    <code>/bin/sh</code>, not a new language.</p>
  </li>
  <li>
    <span class="n">03</span>
    <h3>ASCII or EBCDIC</h3>
    <p>The character set is a compile-time choice and the source assumes
    neither. File tagging, <code>STEPLIB</code> and the z/OS shell behaviours
    scripts rely on are in scope.</p>
  </li>
  <li>
    <span class="n">04</span>
    <h3>An interactive shell too</h3>
    <p>Job control, tab completion, history, emacs and vi editing, with
    bash's key bindings. None of it is initialised by a non-interactive
    shell.</p>
  </li>
</ol>

## How it compares

CPU-seconds (user+sys, children included) from `make bench` / `bench/run.sh`.
The benchmark scripts check each shell's output against the reference shell as
well as timing it, so a wrong answer fails instead of merely being timed.

### z/OS

Measured on z/OS (64-bit ASCII build, with the 64-bit C run-time in the dynamic
LPA), against IBM's `/bin/sh` (`z/OS sh`), bash, zsh and oksh:

| benchmark | zash | z/OS sh | bash | zsh | oksh |
| --- | --- | --- | --- | --- | --- |
| `$(builtin)` x 40000 | 0.04 | 20.63 | 22.44 | 51.34 | 36.49 |
| `(( ))` as a command | 0.14 | n/a | 0.94 | 0.39 | n/a |
| `[[ ]]` in a loop | 0.08 | 0.93 | 1.08 | 0.28 | n/a |
| `[ ]` tests in a loop | 0.12 | 1.40 | 1.62 | 1.10 | n/a |
| `case` dispatch | 0.06 | 0.64 | 0.78 | 0.35 | 0.59 |
| small pipelines and `$(a \| b)` | 0.62 | 1.60 | 4.21 | 6.74 | 3.37 |
| 2000 external commands | 0.49 | 0.52 | 1.55 | 2.87 | 1.39 |
| subshells | 0.00 | 0.78 | 1.32 | 3.66 | 0.80 |
| background jobs | 0.08 | 0.12 | 0.24 | 0.24 | 0.12 |
| redirections | 0.26 | 0.35 | 0.32 | 0.32 | port bug |
| here-documents | 0.31 | 1.09 | 0.72 | 1.03 | n/a |
| `while read` over a file | 0.30 | 0.93 | 0.93 | 3.27 | port bug |
| recursion | 0.04 | 0.24 | 0.28 | 0.22 | 0.20 |
| `printf` | 1.19 | 1.92 | 1.40 | 1.40 | n/a |
| `getopts` | 0.04 | 0.28 | 0.21 | 0.21 | n/a |
| parameter trimming | 0.12 | 0.98 | 0.58 | 0.58 | n/a |
| IFS field splitting | 0.04 | 0.32 | 0.05 | differs | n/a |
| pattern matching and `case` | 0.27 | 3.04 | 0.98 | 0.98 | n/a |
| count a log by level and hour | 0.17 | 0.54 | 1.20 | 1.20 | n/a |
| render and check 100 configs | 0.16 | 0.20 | 0.62 | 0.62 | n/a |
| file tagging and auto-conversion | 0.38 | 1.03 | 2.33 | 2.33 | n/a |

The gap on z/OS is process creation: every command substitution, subshell and
pipeline stage costs a full spawn or address-space copy in the other shells,
whereas zash runs builtin command substitutions, output-only subshells and
`echo`/`print` pipeline stages in-shell. `n/a` means the shell lacks the
feature; `differs` means zsh did not field-split unquoted expansions; `port bug`
reflects output corruption in the third-party `oksh` port.

### Linux x86-64

The same suite on Linux x86-64 via `make bench`, where `fork()` is cheap:

| benchmark | zash | dash | bash | ksh93 | oksh |
| --- | --- | --- | --- | --- | --- |
| `$(builtin)` x 40000 | 0.01 | 8.20 | 17.99 | 0.11 | 25.24 |
| function calls | 0.03 | 0.07 | 0.25 | 0.13 | 0.12 |
| arithmetic loop | 0.07 | 0.19 | 0.53 | 0.24 | 0.31 |
| `let` and integer variables | 0.10 | n/a | 0.78 | 0.35 | 0.43 |
| `(( ))` as a command | 0.06 | n/a | 0.33 | 0.09 | 0.30 |
| `[[ ]]` in a loop | 0.04 | n/a | 0.29 | 0.12 | n/a |
| `[ ]` tests in a loop | 0.05 | 0.16 | 0.43 | 0.15 | 0.22 |
| `case` dispatch | 0.03 | 0.07 | 0.20 | 0.09 | 0.14 |
| small pipelines and `$(a \| b)` | 1.10 | 2.35 | 3.16 | 1.33 | 2.32 |
| 2000 external commands | 0.55 | 0.53 | 0.81 | 0.56 | 0.84 |
| subshells | 0.01 | 0.37 | 0.62 | 0.01 | 0.48 |
| background jobs | 0.03 | 0.03 | 0.06 | 0.04 | 0.03 |
| redirections | 0.07 | 0.08 | 0.11 | 0.09 | 5.85 |
| here-documents | 0.03 | 0.03 | 0.08 | 0.10 | 0.13 |
| `while read` over a file | 0.04 | 0.07 | 0.21 | 0.12 | 0.10 |
| recursion | 0.02 | 0.04 | 0.17 | 0.05 | 0.06 |
| `printf` | 0.09 | 0.12 | 0.23 | 0.16 | 19.70 |
| `getopts` | 0.02 | 0.03 | 0.09 | 0.03 | 0.05 |
| parameter trimming | 0.05 | 0.09 | 0.32 | 0.20 | 0.14 |
| IFS field splitting | 0.03 | 0.04 | 0.11 | 0.05 | 0.06 |
| pattern matching and `case` | 0.11 | 0.18 | 0.53 | 0.38 | 0.35 |
| count a log by level and hour | 0.04 | 0.05 | 0.13 | 0.07 | 0.08 |
| render and check 100 configs | 0.38 | 0.46 | 0.53 | 0.26 | 0.52 |

See the [project README](https://github.com/skurtz97/zash#status) for the
dynamic LPA notes and methodology.

## Get started

```sh
git clone https://github.com/skurtz97/zash
cd zash
make            # Linux: ./zash
make check      # run the suite
```

On z/OS, `make` builds the ASCII `./zash` with IBM Open XL C/C++ and
`make zos-ebcdic` builds the EBCDIC variant. See
[Building zash]({{< relref "docs/install" >}}) for the z/OS targets and the
address-mode notes, and [Development]({{< relref "docs/develop" >}}) for what
the test suite covers.