Re: is_at_eof: request for critique
Brian Wood <woodbrian77@gmail.com> wrote:
[2003 post]
It seems that cout << ist 3x slower than printf().
Could somebody please explain why << is so slow?
Here's what I got after testing similar code (10,000 repetitions of
each)
with MS VC++ 7.1 (using Microsoft's library, including iostreams):
I know that all known implementations of iostream are slower than the
equivalent C stream implementationa (even though in theory the C++ stream
implementations could conceivably be *faster* because there's no need for
format string parsing). However, my attitude towards that is: Know your
tools. If you need extreme I/O speed, use the C stream functions (but be
aware of their problems). If you don't need speed and prefer safety and
versatility, use the C++ streams.
This is no different from chosing your data containers approperiately:
std::vector is good for some things and std::set for others. With one you
get compromises you don't get with the other (eg. std::vector consumes
less memory and keeps all elements in adjacent memory locations, but
pointers and iterators get invalidated if you add new elements, while the
opposite is true for std::set.) You always have to choose appropriately.