With the new 5.0 version of bash just out I thought it was a good time to examine the speed and resource usage of the various shells that are available for interactive use.
To test the speed I am using a simple iterative loop:
for i in $(seq 1 1000000); do [ 1 = 1 ]; done
Each test was run three times with the best result selected.
And for resource usage I have trusty old
ps_mem.py, which is available in [Community]:
The shells are under test are
zsh (ArchLabs’ default interactive shell),
mksh (which is used as the default shell in the Android operating system),
dash (Debian’s default /bin/sh replacement, optimised for speed at the expense of fancy features),
ash (the Almquist shell variant provided by
busybox) and finally AT&T’s venerable
ksh93 (this used to cost quite a lot of money before it was open-sourced).
Without further ado, here are the results (in alphabetical order)…
0m01.86s real 0m01.57s user 0m00.31s system 552.0 KiB + 44.5 KiB = 596.5 KiB busybox
0m03.31s real 0m03.24s user 0m00.08s system 2.4 MiB + 79.5 KiB = 2.5 MiB bash
0m01.10s real 0m01.07s user 0m00.04s system 196.0 KiB + 29.5 KiB = 225.5 KiB dash
0m00.84s real 0m00.82s user 0m00.03s system 1.7 MiB + 74.5 KiB = 1.7 MiB ksh93
0m01.98s real 0m01.97s user 0m00.03s system 664.0 KiB + 101.5 KiB = 765.5 KiB mksh
0m04.88s real 0m04.13s user 0m00.76s system 1.9 MiB + 93.5 KiB = 2.0 MiB zsh
I did these tests a while ago with older versions of
bash has sped up slighly (which surprised me) and
zsh has become slightly slower (more features added, perhaps?).
ksh93 look very tempting, I find
dash too limited in respect of features (no here strings or tab-completion, which is a real deal-breaker for me) and I have it on good authority (from the people currently working on the next version) that
ksh93 has many bugs due to it’s advanced decrepitude.
For me personally, I like
mksh best for it’s mix of speed, low memory usage and functionality — it doesn’t do associative arrays (AFAICT) but I’ve never used those interactively so that’s not really a problem. It’s status as Android’s default shell also means lots of users and “eyes on the code”, which should reduce bugs & vulnerabilities, at least theoretically.
To change the default shell for your user, run
chsh -s $(which $shell)
$shell with the name of the desired shell.
Thanks for reading!