Re:Why is reading lines from stdin much slower in C++ than P...
by meastham on Saturday March 10, 2012 @10:23PM
(#3689444)
That's quite a lot to read into a tiny example like this.
[ Parent
| on HN ]
Re:Why is reading lines from stdin much slower in C++ than P...
by _delirium on Saturday March 10, 2012 @10:43PM
(#3689472)
I agree, though I think it could fairly be taken as one small bit of evidence in favor of "C++ has a lot of gotchas". In this case it looks like the culprit is C++'s C-compatibility-driven decision to sync with stdio by default, and therefore to avoid buffering input. Of course, if they made the opposite decision on defaults, "C++ doesn't sync with stdio by default" would be a different, probably also common, variety of "gotcha".
Re:Why is reading lines from stdin much slower in C++ than P...
by mikeash on Sunday March 11, 2012 @07:09AM
(#3690151)
Why isn't cin implemented on top of C's stdin and FILE? That way you get both buffering and compatibility.
Re:Why is reading lines from stdin much slower in C++ than P...
by jemfinch on Sunday March 11, 2012 @11:44AM
(#3690526)
I've not implemented the C++ std library, but my guess is it's because iostreams need to implement their own buffering anyway, so it would just add complexity and unpredictability to buffer atop an already-buffering library.
Re:Why is reading lines from stdin much slower in C++ than P...
by mikeash on Sunday March 11, 2012 @09:51PM
(#3692005)
I'm not sure this quite makes sense. The buffering can already be disabled, clearly, since that's what's being discussed. The non-buffering implementation could be easily placed atop FILE (I don't know the details, but I can't imagine a FILE-based iostream implementation being at all complex) at which point you have a buffered implementation that also cooperates with pure C stdio. iostream would need buffering for other operations, but could just leave it off permanently for stdio, and the switch already exists.