Comparing SH, BASH, KSH, and ZSH Speed | by Shinichi Okada | Feb, 2021


The winner is going to…drumroll…

Photo by paolo candelo on Unsplash

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.

My MacBook Pro spec. Image by Author.

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 <>
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.

The ShellBench pattern exams main points

I used all pattern exams for sh, bash, ksh, and zsh.

Test instance of Shellbench. Image by Author.

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.

One of “assign and cmp” take a look at effects. Image by Authro.

rely and eval

One of “rely and eval” take a look at effects. Image by Author.

func and null

One of “func and null” take a look at effects. Image by Author.

output and subshell

One of “output and subshell” take a look at effects. Image by Author.

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 sh-benchmark take a look at main points. Image by Author.
One of my results. Image by Author.

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

A — G take a look at effects.
H — N take a look at effects.

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.


You can clone Shellbench, make the shellbench report executable, and run the script:

$ ./shellbench -s sh,bash,ksh,zsh pattern/ pattern/


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.


Please enter your comment!
Please enter your name here