Xref: utzoo comp.sys.m6809:732 comp.lang.c:8308 Path: utzoo!mnetor!uunet!littlei!omepd!mipos3!td2cad!tp From: tp@td2cad.intel.com (t patterson) Newsgroups: comp.sys.m6809,comp.lang.c Subject: Re: Don't use Scanf() Message-ID: <762@td2cad.intel.com> Date: 17 Mar 88 21:41:32 GMT References: <2401@ihwpt.ATT.COM> <320@c10sd1.StPaul.NCR.COM> <1185@ucsfcca.ucsf.edu> <9241@sunybcs.UUCP> <1140@csun.UUCP> <2980@haddock.ISC.COM> Reply-To: tp@td2cad.UUCP (t patterson) Followup-To: comp.lang.c Organization: Intel CTD SC-9 Lines: 82 Keywords: C stdio library In article <2980@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >In article <1140@csun.UUCP> sef@csun.UUCP (Sean Fagan) writes: >>printf("Hello world!\n") is slower than puts("Hello world!") which is slower >>than write(1,"Hello world!\n",13). > >Using write() instead of the stdio routines is not necessarily a win, because >non-UNIX systems may still have to fiddle with e.g. NL vs. CRLF conversions. >Also note that (even on UNIX) the buffering which is usually done in stdio may >let you write everything with a single system call; this can make stdio faster >than multiple calls to write(). for those of you arguing about the relative merits of printf, puts, and write, here's some times for each of the three writing "hello world\n" to /dev/null 100,000 times on a uVAX II running Ultrix 2.0: printf 18 sec (wall-clock time, not user or sys time) puts 15 sec write 59 sec following is a script of what I did (with white space added), then the source of the three test programs. such a simple test doesn't say a whole lot. decide for yourself what it means. Script started on Thu Mar 17 13:11:17 1988 ctdone> time tprintf >/dev/null 17.3u 0.5s 0:18 98% 7+21k 0+0io 0pf+0w ctdone> time tputs >/dev/null 14.6u 0.4s 0:15 99% 4+21k 0+0io 0pf+0w ctdone> time twrite >/dev/null 5.1u 53.4s 0:59 98% 1+3k 0+0io 0pf+0w ctdone> time tprintf >/usr/tmp/t 17.4u 1.9s 0:19 98% 7+21k 5+154io 0pf+0w ctdone> time tputs >/usr/tmp/t 14.8u 1.9s 0:17 97% 3+21k 6+155io 0pf+0w ctdone> time twrite >/usr/tmp/t 4.7u 346.4s 6:02 96% 1+3k 7+192io 0pf+0w ctdone> script done on Thu Mar 17 13:23:56 1988 tprintf.c: main() { int i; for ( i = 100000; i > 0 ; i-- ) { printf("hello world\n"); } exit(0); } tputs.c: main() { int i; for ( i = 100000; i > 0 ; i-- ) { puts("hello world"); } exit(0); } twrite.c: main() { int i; for ( i = 100000; i > 0 ; i-- ) { write(1, "hello world\n", 12); } exit(0); } -- ..tp.. t patterson domain: tp%td2cad.intel.com@relay.cs.net path: {ihnp4,cbosgd,uunet}!wucs1!tp {pyramid,hoptoad}!td2cad!tp {decwrl,hplabs,oliveb}!intelca!mipos3!td2cad!tp