Why is reading lines from stdin much slower in C++ than Python?
stackoverflow.com
stackoverflow.com
I'm asking to the larger Hacker News community here, how do you illustrate the dependencies of a standard library API call without making it more complicated? Syntax is nothing, understanding is everything.
cin.sync_with_stdio(false);
http://www.joelonsoftware.com/articles/LeakyAbstractions.htm...
Sorry, I couldn't resist - you are of course right with the general stdio over std::iostream thing, though. I've also found that memory usage and executable size explode when using streams - though that's not C++'s fault per se, more a stdlib/compiler problem.
Edit: Several (more or less successful) attempts have been made for an alternative library. http://accu.org/index.php/journals/1539 for an overview.
I am a real world C++ programmer, I can only claim about 5 years experience though, and I use iostream. So yes, your data is anecdotal, so is mine, and we are both complete opposites.
See "Useless use of cat awards" from days of yore: http://partmaps.org/era/unix/award.html#uucaletter
cat(1) almost certainly internally buffers data (32KB here) thus context switches occurs. Shell creates pipe which is buffered inside kernel.
All of this muffles measurements.
What was one or several read(2) calls + processing is now one or several calls of maybe smaller sizes + whatever scheduling differences + in one of the examples OP used /usr/bin/time of the whole thing also.
This is of course is not visible because data were dumbed down by using time() which has horrible granularity, but when finer grained timer it'd be visible, I'm sure.