tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: mksh import

On Thu, Dec 30, 2010 at 05:10:10PM +0000, David Laight wrote:

> On Thu, Dec 30, 2010 at 09:28:06AM -0500, Alex Goncharov wrote:
> > ,--- You/Thor (Thu, 30 Dec 2010 08:43:16 -0500) ----*
> > | Another question is performance.  Some shells are much much faster than
> > | others for tasks like system builds.  For example, zsh can actually
> > | speed up the build considerably if used to replace our /bin/sh,
> > 
> > Is there more information on this -- even at the perception-like
> > level?  It sounds surprising that spawning mostly (?)  compilation
> > processes is comparable, in execution time, to completing the
> > nontrivial work of those spawned processes.
> > 
> > Where does bash fall in terms of performance?
> Generlly executing shell functions and loops.
> These are VERY slow with bash and the ksh in netbsd's source tree.
> netbsd's /bin/sh parses shell constructs to an intermediate tree and
> then evaluates the tree - so the text isn't repeatedly parsed.
> This might be a slight loss for simple commands (including those
> from scripts) but is a massive gain for anything complicated.
> If you are tring to measure shell performance you do need to ensure
> that nothing has to be exec'ed.

Making another attempt to make a very basic benchmark, I constructed
a quick program that will test the shell executing a triply nested
loop executing a command of "echo -n", "/bin/echo -n" and "$SHELL
-c '/bin/echo -n'".  The "echo -n" loop over much larger sets to
get the numbers high enough to be reasonable.

The results are pretty good on my laptop for /bin/sh:

$ /tmp/   
                       builtins  externals  via sh -c
/bin/sh                    1.03       4.89      14.68
/bin/ksh                   2.07       8.17      22.72
/usr/pkg/bin/mksh          2.53       8.67      22.55
/usr/pkg/bin/bash         29.64       8.26      20.01
/usr/pkg/bin/zsh           2.51       9.00      24.50

Obviously, this is not an exhaustive test or probably indicative
of a real world use case.  It does, however, seem to indicate that
both ksh's are substantially slower for this particular workload
than /bin/sh and that bash is quite poor with these kinds of large

The script is below:


FMT="%- 20.20s % 10.10s % 10.10s % 10.10s\n"
output() {

        T1="$(echo "$2" | awk '{print $1}')"
        T2="$(echo "$3" | awk '{print $1}')"
        T3="$(echo "$4" | awk '{print $1}')"

        printf "$FMT" "$S" "$T1" "$T2" "$T3"

the_test() {
        NUMBERS="$(echo "$3" | tr '\012' ' ')"

        TIME=$(2>&1 time $SHELL -c "
                for i in $NUMBERS; do
                        for j in $NUMBERS; do
                                for k in $NUMBERS; do

        echo "$TIME"

run_test() {

        T1="$(the_test "$S" "echo -n"                   "$(jot 100)")"
        T2="$(the_test "$S" "/bin/echo -n"              "$(jot  20)")"
        T3="$(the_test "$S" "$S -c '/bin/echo -n'"      "$(jot  20)")"

        output "$S" "$T1" "$T2" "$T3"

printf "$FMT" "" "builtins" "externals" "via sh -c"

for S in /bin/sh /bin/ksh /usr/pkg/bin/mksh /usr/pkg/bin/bash /usr/pkg/bin/zsh;
        run_test "$S"

    Roland Dowdeswell                      http://Imrryr.ORG/~elric/

Home | Main Index | Thread Index | Old Index