Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-03-13 14:50:38


The quick answer to my questions using a naive test of a for loop of 100000

(times in seconds)

cout << 'x';
cout << '\n';
cout << newl;
cout << endl;
cout << "\n";

MSVC 7.0 debug mode 'strict'

to console:
char time 5.898
'\n' time 3.275
newl time 3.545
endl time 3.395
C string "\n" time 3.345

to a txt file:
char time 0.11
'\n' time 0.12
newl time 0.18
endl time 0.651 <<<< flush cost?
C string "\n" time 0.13

release mode 'strict'
to console:
char time 5.888
'\n' time 3.074
newl time 3.075
endl time 3.004
C string "\n" time 3.115

to a txt file:
char time 0.09
'\n' time 0.1
newl time 0.12
endl time 0.661 <<<< flush cost?
C string "\n" time 0.1

I am left with a suspicion that fools step in where angels fear to tread, but
...

this suggests that there is a modest but useful advantage to avoiding the
flushing cost by encouraging newl instead of endl. This does not apply to
console if, as is the case here, each char outputs is flushed.

(The longer time for cout char does not seem to be an artefact).

Paul

> -----Original Message-----
> From: Paul A. Bristow [mailto:boost_at_[hidden]]
> Sent: Wednesday, March 12, 2003 11:36 AM
> To: Boost mailing list
> Subject: RE: [boost] Re: I/O library formal review
>
>
> > -----Original Message-----
> > From: boost-bounces_at_[hidden]
> > [mailto:boost-bounces_at_[hidden]]On Behalf Of Gennadiy Rozental
> > Sent: Tuesday, March 11, 2003 10:15 PM
> > To: boost_at_[hidden]
> > Subject: [boost] Re: I/O library formal review
> >
> > > * newl needs a bit more rationale. How is cout << newl different from
> > cout
> > > << '\n'? How is it better?
> >
> > Maybe newl does not reset the manipulators? If it true it should be spelled
> > out explicitly. In any case I also like to see an example where newl is
> > preferable to << '\n'.
>
> Is there a speed advantage - because flush is quite expensive?
> We should have some evidence for this?
>
> Paul
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk