Skip to content

Instantly share code, notes, and snippets.

@mlafeldt
Created January 23, 2012 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlafeldt/1663556 to your computer and use it in GitHub Desktop.
Save mlafeldt/1663556 to your computer and use it in GitHub Desktop.
[Shell] Simple performance test for POSIX-compliant shells
$ time env -i bash shell-perf.sh
Forking 1000 bash subshells........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
real 0m10.797s
user 0m11.250s
sys 0m1.380s
$ time env -i dash shell-perf.sh
Forking 1000 dash subshells........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
real 0m4.253s
user 0m9.590s
sys 0m0.550s
$ time env -i zsh shell-perf.sh
Forking 1000 zsh subshells........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
real 0m8.384s
user 0m9.240s
sys 0m2.070s
$ uname -a
Linux pc-mlafeldt 2.6.32-37-generic #81-Ubuntu SMP Fri Dec 2 20:32:42 UTC 2011 x86_64 GNU/Linux
$ grep "^model name" /proc/cpuinfo
model name : Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
model name : Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
model name : Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
model name : Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
#!/bin/sh
# Simple performance test for POSIX-compliant shells
#
# Usage: time env -i <shell> shell-perf.sh [<num subshells>]
#
# Written by Mathias Lafeldt <mathias.lafeldt@gmail.com>
shell="$(ps -o pid,command | awk "\$1 == $$ { print \$2 }")"
forks=${1:-1000}
echo -n "Forking $forks $shell subshells"
for i in $(seq 1 $forks); do
"$shell" -c 'echo -n .; j=1; while [ $j -le 1000 ]; do j=$(($j+1)); done'
done
echo ""
@mlafeldt
Copy link
Author

More results:

env -i bash shell-perf.sh  20.46s user 2.99s system 94% cpu 24.918 total
env -i zsh shell-perf.sh  10.36s user 3.42s system 80% cpu 17.213 total
env -i dash shell-perf.sh  5.92s user 0.92s system 81% cpu 8.378 total

Thanks to Stefan S.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment