Closed jiannanya closed 1 day ago
Perhaps related to #3669.
Yeah, I think it's a duplicate.
@jiannanya Consider to use buffering output, setvbuf(stdout, nullptr, _IOLBF, 16384);
This indeed seems related but we're not quite willing to resolve this as a duplicate yet, as this issue is talking about the absolute performance difference (which could have multiple causes), and sync_with_stdio
is just one cause.
I think it might have something to do with operator<<.
operator<< is a user-defined operator here, so it’s actually a function, every operator<< call locks the buffer, but the printf locks the buffer only once (I dunno how it actually works, but I don’t think it has to be locked multi times)
I’ve tested the example above, if we just call operator<< once, the speed of count is similar to printf
Thanks, that sounds correct to us. We're going to close this as half by design (repeatedly calling operator<<
is of course more expensive) and half duplicate of #3669.
Describe the bug
The default std::cout does much slower output to default console than printf,even use sync_with_stdio(false) .
Command-line test case
Expected behavior
The speed of std::cout is similar to the printf's.
STL version
My Local test result