Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watmath.UUCP Path: utzoo!watmath!idallen From: idallen@watmath.UUCP Newsgroups: net.unix-wizards Subject: Relative speed of Bourne vs. C Shells - C Shell is faster. Message-ID: <12138@watmath.UUCP> Date: Sun, 24-Mar-85 12:47:45 EST Article-I.D.: watmath.12138 Posted: Sun Mar 24 12:47:45 1985 Date-Received: Mon, 25-Mar-85 01:47:30 EST References: <216@sdcc12.UUCP> Reply-To: idallen@watmath.UUCP (Ian! D. Allen) Organization: U of Waterloo, Ontario Lines: 37 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