incrementing variables

Jeffrey Gleixner glex at uh.msc.umn.edu
Thu Mar 29 13:23:28 AEST 1990


A couple of weeks ago someone asked how to increment a variable in Bsh and
in response to that it was mentioned that writting a C program to do it
would be much quicker.   I wondered how much faster it would actually be
and here's what I experienced.

%> cat t1
#!/bin/sh
count=0
while [ "$count" -lt "250" ]; do
        count=`expr $count + 1`
done
echo "count = $count"

%cat t2
#!/bin/sh
count=0
while [ "$count" -lt "250" ]; do
 count=`a1 "$count"`
done
echo "count = $count"

%>cat a1.c
#include <stdio.h>
main(argc,argv)
int argc; char *argv[]; {printf("%d",atoi(argv[1])+1);}

%> time t1
count = 250
7.5u 19.5s 0:31 85% 0+88k 1+3io 0pf+0w

%> time t2 
count = 250
7.3u 17.9s 0:29 85% 0+88k 1+3io 0pf+0w

I don't really see that much of an increase.  This was on a Sun 4/280.  If
it can be done more efficiently please E-Mail me 'cause I'm curious.  I also
tried using BC instead of the C program and that was horrible.  Any examples?

Thanks.
glex at msc.umn.edu  ===  " I don't date any girl that says bitch'n " ===



More information about the Comp.unix.questions mailing list