Re: What influences C++ I/O performance?
* peter koch:
On 16 Feb., 22:19, rpbg...@yahoo.com (Roland Pibinger) wrote:
On Sun, 3 Feb 2008 06:04:39 -0800 (PST), SzH wrote:
I would like to read in large integer matrices from text files, as
quickly as possible.
...
It is more likely
that there are some relevant settings for iostreams (with a
significant impact on performance) that I am not aware of.
Any suggestions for making this program perform well portably would me
most welcome!
Avoid iostreams. They are slow 'by design'. Just try to figure out how
often reallocation and copying occur in your code.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Why do you believe that iostreams are slow by design?
I think the belief that the inefficiency may or must be related to the
design, primarily stems from the virtual absence of efficient
implementations. Bjarne indicated in 2001[1] that an efficient iostream
implementation was very high on his wish-list, but that he only expected
that to be possible for a simple subset of operations, "I believe that
aggressive optimization techniques will allow us to regain the
efficiency of the original in the many common cases where the full
generality of iostreams is not used". As far as I know, as of 2008
Bjarne has not yet had his wish granted: e.g., Andrei's fabled YASTLI
implementation seems to still only have status of Good Idea.
And what would
you suggest instead? The printf family certainly is slow by design,
replacing a compiled language with an (obscure) interpreted one -
namely the language specified by the format specifier.
There is unfortunately, AFAIK, no general, good replacement.
However, where efficiency matters, one may try using FILE*, which is
generally more efficient, before going down to system APIs.
Cheers, & hth.,
- Alf
Disclaimer: it's been some years since last I measured file i/o
performance, however, I have seen no evidence to the contrary.
Notes:
[1] <url: http://research.att.com/~bs/01chinese.html>
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?