I\'m timing the difference between various ways to print text to standard output. I\'m testing cout
, printf
, and ostringstream
using both
Each output operation on a stream dors multiple steps:
endl
calls an extra virtual function on the stream buffer.I would personally expect that the extra virtual function call actually has relativly small impact compared to the other operations. You can verify this guess by also profiling this output:
out << "stream" << '\n';
... or even
out << "stream" << out.widen('\n');
That said, there are a number of improvements which a stream implementation can apply to cut down on checks. Whether this is done will depend on the implementation, of course.