Huge performance bottleneck with cin.read.
Gabriel Dos Reis
gdr@codesourcery.com
Sun Apr 1 00:00:00 GMT 2001
Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr> writes:
[...]
| > Please, could fill in a bug-report and mark it as a regression?
|
| Done.
Thanks very much.
| > | The crux of the problem seem to be (in fstream.tcc).
| > |
| > | // XXX So that istream::getc() will only need to get 1 char,
| > | // as opposed to BUF_SIZE.
| > | if (__fd == 0)
| > | _M_buf_size = 1;
| > |
| > | Consequently, characters are read one by one which is extremely
| > | costly.
| > |
| > | Is this absolutely necessary (I cannot find support for this in the
| > | standard, but my reading has been quick)???
| > |
| > | If yes, how can we avoid this behaviour for the read function:
| >
| > sync_with_stdio()?
|
| OK, Benjamin suggest the same idea. I do not exactly
| understand how this should work. Does it mean to implement cin.read
| in terms of fread on stdin ???
sync_with_stdio(false) indicates that I/O won't be messed up with
stdio trafics, so one would expect performance gain -- if that doesn't
happen, then that should qualify as a bug (yes, one might argue that
that is an QoI but I don't want to take that route).
| bkoz@redhat.com said:
| > looks like the only performance hit is on cin/cout/cerr. This is to be
| > expected: they are no longer buffered. I'm just relieved that normal
| > string/file streams are ok, which is cool. I would actually expect
| > stringstreams to be faster than the old memory-based stream
| > implementation.
|
| Well, I saw it only on input (and the piece of code I quoted seem to
| support that).
|
| Is this unbuffered behaviour mandated by the standard (I did not find
| any reference to this) ??
No. But that is the price you pay for an implementation of top of
C-stdio faiclities. Once we're back to libio-land (I don't know
when) I expect us to deliver better performance.
(The I/O internal implementation details are tricky to get right in
addition of good performance criteria)
| Actually, I thought that all but cerr were buffered (cerr being the
| unbuffered version of clog), but that's from my old Stroustrup book.
They are.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com
More information about the Libstdc++
mailing list