Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!uc!uh!glex From: glex@uh.msc.umn.edu (Jeffrey Gleixner) Newsgroups: comp.unix.questions Subject: incrementing variables Message-ID: <1508@uc.msc.umn.edu> Date: 29 Mar 90 03:23:28 GMT Sender: news@uc.msc.umn.edu Reply-To: glex@uh.UUCP (Jeffrey Gleixner) Organization: Minnesota Supercomputer Center, Minneapolis, MN Lines: 40 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 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@msc.umn.edu === " I don't date any girl that says bitch'n " ===