I incessantly listen and learn that Bash is sluggish. So I spent one weekend checking how sluggish it’s. I used two strategies. The first one is ShellBench. The ShellSpec created a benchmark application for POSIX shell comparability. The 2nd one is the sh-benchmark script created by @satoh_fumiyasu.
I take advantage of a MacBook Pro.
And those are my sh
, bash
, ksh
, and zsh
variations:
❯ sh --version
GNU bash, edition 3.2.57(1)-release (x86_64-apple-darwin20)
Copyright (C) 2007 Free Software Foundation, Inc.❯ bash --version
GNU bash, edition 5.1.4(1)-release (x86_64-apple-darwin20.2.0)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL edition Three or later <http://gnu.org/licenses/gpl.html>This is unfastened device; you might be unfastened to switch and redistribute it.
There is NO WARRANTY, to the level authorized by legislation.❯ ksh --version
edition sh (AT&T Research) 93u+ 2012-08-01❯ zsh --version
zsh 5.8 (x86_64-apple-darwin20.0)
You can run a take a look at with any shells, sh
, bash
, ksh
, mksh
, posh
, zsh
, and so on with ShellBench. It returns the selection of executions according to 2nd. It supplies 8 sample benchmark tests.
The ShellBench counts the selection of occasions a pattern code is done. The “assign pattern take a look at” exams assigning a variable in numerous tactics, the “rely pattern take a look at” exams alternative ways of counting, and so on.
I used all pattern exams for sh
, bash
, ksh
, and zsh
.
Here is a table from one in every of my effects.
The exams go back the selection of executions according to 2nd and this implies taller graphs are higher ends up in the next graphs.
assign and cmp
sh
: Blue, bash
: Yellow, ksh
: Green, zsh
: Red.
rely and eval
func and null
output and subshell
The ksh
and zsh
turns out about seven occasions quicker than bash
. The ksh
excelled in 17 exams and the zsh
in six exams.
The sh-benchmark exams on parameter expansions, array parameter expansions, mathematics opinions, exams, and iterate parameters.
The script returns effects relative to the bash effects. All numbers are in share. So smaller numbers suggest quicker.
bash
: Blue, ksh
: Yellow, zsh
: Green
The zsh
was once the quickest in six exams and the ksh
was once the quickest in seven exams.
Interestingly zsh
was once very sluggish for the Fork take a look at.
If you wish to have to check it your self you’ll be able to apply this.
Shellbench
You can clone Shellbench, make the shellbench
report executable, and run the script:
$ ./shellbench -s sh,bash,ksh,zsh pattern/rely.sh pattern/output.sh
sh-benchmark
Copy sh-benchmark.zsh and sh-benchmark-scripts into the similar listing. Make the sh-benchmark.zsh executable and run it for your terminal:
$ sh-benchmark.zsh
According to my exams, ksh
is the winner and zsh
is the runner-up. Both shells are 2–30 occasions quicker than bash
relying at the take a look at.
If you utilize bash
for lower than 100 traces as Google Shell Style Guide suggests, then I don’t suppose you’re going to realize the adaptation. Although it’ll after all rely at the activity.