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 --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,
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
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
rely and eval
func and null
output and subshell
zsh turns out about seven occasions quicker than
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.
zsh was once the quickest in six exams and the
ksh was once the quickest in seven exams.
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.
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
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.