Relative speed of Bourne vs. C Shells - C Shell is faster.

idallen at watmath.UUCP idallen at watmath.UUCP
Mon Mar 25 03:47:45 AEST 1985


I'm surprised at the comments that the Bourne Shell is faster than the
C Shell.  The 4.2bsd Bourne Shell has to call a program to add two
numbers together, print a message, or perform an IF statment -- the C
Shell does all that using built-in code.  Waterloo has some large shell
scripts that would not be practical if written in Bourne format.

I don't like the C Shell bugs, but when I can work around them the C
Shell gives me much faster performance for my large shell scripts.
KSH recognized the cost of calling programs to do simple things (such
as add or compare numbers), and moved all that code into the shell
itself.   Perhaps other Bourne Shells have done this, but be sure that
your version does before you claim it is faster than the C Shell.

For comparison:
-------------------------------------------------------------------------
#!/bin/csh -f
@ x=1
while ( $x < 100 )
	@ x++
	if ( $x > 10 ) echo Hi! $x
end
-------------------------------------------------------------------------
#!/bin/sh
x=1
while [ $x -lt 100 ]; do
	x=`expr $x + 1`
	if [ $x -gt 10 ]; then
		echo Hi! $x
	fi
done
-------------------------------------------------------------------------
On our VAX/780 running 4.2bsd, the Bourne script uses 25 seconds user CPU
and 138 seconds system CPU.  The C Shell script uses 11 seconds user CPU
and 4 seconds system CPU.  The Bourne script has to fork four processes
for each loop iteration; the C Shell none.
-- 
        -IAN!  (Ian! D. Allen)      University of Waterloo



More information about the Comp.unix.wizards mailing list