Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link ×

Chilli's blog

By Chilli, history, 21 month(s) ago, In English,

It seems that in C++11, even with the standard ios::sync_with_stdio(0), cin.tie(0); hacks, has significantly slower I/O with cin/cout than C++14.

View these submissions:
- cin/cout && C++11: 2963ms here
- cin/cout && C++14: 1934ms here

With scanf/printf, this issue isn't there:
- scanf/printf && C++11: 2027ms here
- scanf/printf && C++14: 1887ms here

I was unaware of this. Does anybody have any explanations? Am I missing something specific about my submissions?

Thanks tonynater for the discussion.

  • Vote: I like it
  • +43
  • Vote: I do not like it

21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Chilli (previous revision, new revision, compare).

21 month(s) ago, # |
  Vote: I like it +25 Vote: I do not like it

Pay attention that Codeforces for C++11 is using an older version of GCC than for C++14. Most likely with different version of standard library. It is much more likely that difference in time is caused by newer version of compiler and standard library than C++ language version.

Seeing that newer version is faster it seems kind of reasonable that compiler makers are improving things instead of making things worse.

There was similar discussion on Codeforces a while ago that included analysis of standard library code. If you find it please add a link here. I can't remember if that time newer version was faster or slower.

Two different implementations will have some difference in performance. Unless both of them are made with goal of getting maximum performance at any cost it might be quite big. Speed isn't the only thing compiler/standard library makers need to optimize. There are things like size, memory usage, maintainability and correctness. Performance might even differ depending on use case, code that works faster in one situation might be slower in different. Performance in standard library needs to be good but not perfect. In situation where maximum performance is really necessary it would probably be possible to improve even further by using custom solution that takes in to account use case specific limitations and requirements.

I would suggest not thinking about it too hard. Keep in mind that without further testing your observation only applies to those specific compiler versions currently used by CodeForces. There might even be differences between different GCC windows builds (mingw,cygwin,tdm-gcc,mingw64) of the same gcc version. On a different judge with different configurations results can be completely different. Compiling the source you linked on my computer with -std=c++11 and -std=c++14 resulted in identical binaries.

21 month(s) ago, # |
  Vote: I like it -24 Vote: I do not like it

Use C++17 you noobs.