Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site tekcrl.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!houxm!vax135!cornell!uw-beaver!tektronix!tekcrl!toddb From: toddb@tekcrl.UUCP (Todd Brunhoff) Newsgroups: net.unix-wizards Subject: Re: Relative speed of Bourne vs. C Shells - C Shell is faster. Message-ID: <84@tekcrl.UUCP> Date: Thu, 28-Mar-85 16:07:15 EST Article-I.D.: tekcrl.84 Posted: Thu Mar 28 16:07:15 1985 Date-Received: Sun, 31-Mar-85 02:41:36 EST References: <216@sdcc12.UUCP> <12138@watmath.UUCP> Reply-To: toddb@tekcrl.UUCP (Todd Brunhoff) Organization: Tektronix, Beaverton OR Lines: 59 In article <12138@watmath.UUCP> idallen@watmath.UUCP (Ian! D. Allen) writes: >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 I consider that a rather silly comparison since neither shell was designed for numeric processing. You wouldn't use Fortran or C for evaluating predicates like you would find in Prolog, etc, etc. A better solution for your "application" (which uses about .8u and 1.2s) would be #!/bin/sh awk ' BEGIN { x = 1; while (x < 100) if (x++ > 10) print "Hi!" x exit }' Nevertheless, your point is well taken; the Bourne shell is slower for using the loops that you used. However, I should have to agree with the "others" that claim the Bourne shell is faster when using the right vernacular. For instance, you should be using "case-esac" and "for" loops instead of the [ commands.