> -------- Original Message -------- > Subject: Re: Using argv[1] in C program > From: "Jerry Davis" > Date: Sun, January 16, 2005 9:05 am > To: plug-discuss@lists.plug.phoenix.az.us > [snip] > #include > > void usage(void); > > int main(int argc, char** argv) { > if ( argc > 1 ) { > if (isdigit(argv[1][0])) { > usleep((unsigned long) atol(argv[1])); > return(0); > } > if ((strcmp(argv[1],"--usage") == 0)) { > usage(); > return(0); > } else { > printf("\nusleep: bad argument %s: unknown option\n",argv[1]); > usage(); > return(-1); > } > } > usage(); > return(-1); > } > > void usage(void) { > printf("usage: usleep [--usage] [microseconds]\n"); > } > [/snip] Thank you to all that participated in this fun little script, I learned a couple things :) I have replaced my system's usleep binary with a compile of the above code. How much overhead does adding stdio.h add? I mean if I want to usleep 1000, in order to be accurate, I would want the usleep binary to be as small as possible. So, I mini benchmarked it... usleep2 is the stripped down version without stdio.h usleep is the full version stdio.h and useage output let i=0; time while [ $i -lt 1000000 ]; do let i=$i+100; ./usleep2 1000; done real 0m59.565s user 0m5.230s sys 0m15.377s let i=0; time while [ $i -lt 1000000 ]; do let i=$i+100; ./usleep 1000; done real 0m59.201s user 0m5.099s sys 0m15.429s Looks like including stdio.h makes it a tad faster! Just kidding, the variance is so small it can be disregarded. Cool. --------------------------------------------------- PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us To subscribe, unsubscribe, or to change you mail settings: http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss