Article View: rec.games.programmer
Article #2021Re: cout vs printf speed (was: Should I learn C or C++ first?)
From: Matt Austern
Date: Tue, 29 Aug 1995 23:39
Date: Tue, 29 Aug 1995 23:39
23 lines
2105 bytes
2105 bytes
In article <41vst0$9nb@gap.cco.caltech.edu> <lemahieu@paradise.caltech.edu> writes: > I was under the impression that cout and cin for I/O was actually _faster_ > than using printf. I thought this was because printf must parse > the format string each time to determine how the subsequent parameters > are to be interpreted and output, whereas this is done at compile time > for cout. The format string is typically constant but must be reparsed every > time the printf function is called, which doesn't sound very efficient to me. There's no reason why printf() has to be implemented like that. Functions in the standard library don't have to be treated as ordinary functions: an implementation is free to treat them as (almost) part of the language. There's nothing wrong with a C++ implementation parsing printf's format string at compile time, doing error checking to make sure that there aren't any type errors, and putting in the appropriate low-level calls. I don't know the names of any implementations that actually do this, but I strongly suspect that there are some. -- Matt Austern He showed his lower teeth. "We matt@physics.berkeley.edu all have flaws," he said, "and http://dogbert.lbl.gov/~matt mine is being wicked."
Technical Details
Message-ID:
<MATT.95Aug29163934@godzilla.EECS.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!mattReferences:
<DDJ2Lp.3DG@pentagon-ai.army.mil> <41afe9$d10@newsbf02.news.aol.com> <41kici$p4t@deyke3.fc.hp.com> <41ngln$qau@druid.borland.com> <41tjep$2hn@deyke3.fc.hp.com> <41v8k9$jq8@tpd.dsccc.com> <41vst0$9nb@gap.cco.caltech.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!matt From: matt@godzilla.EECS.Berkeley.EDU (Matt Austern) Newsgroups: rec.games.programmer,comp.lang.c++ Subject: Re: cout vs printf speed (was: Should I learn C or C++ first?) Date: 29 Aug 1995 23:39:34 GMT Organization: University of California at Berkeley (computational neuroscience) Message-ID: <MATT.95Aug29163934@godzilla.EECS.Berkeley.EDU> References: <DDJ2Lp.3DG@pentagon-ai.army.mil> <41afe9$d10@newsbf02.news.aol.com> <41kici$p4t@deyke3.fc.hp.com> <41ngln$qau@druid.borland.com> <41tjep$2hn@deyke3.fc.hp.com> <41v8k9$jq8@tpd.dsccc.com> <41vst0$9nb@gap.cco.caltech.edu> Reply-To: matt@physics.berkeley.edu NNTP-Posting-Host: godzilla.eecs.berkeley.edu In-reply-to: 's message of 29 Aug 1995 20:21:52 GMT