C++ Class Templates

  • + 0 comments

    As many have noticed, some test cases fail due to timeout when submitting under C++ 14 or C++ 20 but not when submitting for C++ 11.

    It has also been pointed out that disabling ios_base::sync_with_stdio at the top of main() resolves the issue. Disabling this syncronization "... the C++ standard streams are allowed to buffer their I/O independently, which may be considerably faster in some cases." - https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio.html

    I was curious why C++ 11 would be faster or not suffer from this issue, so I went poking around Compiler Explorer (https://godbolt.org/). I was not able to find any difference in various GCC versions and only minor differences with Clang when compiling with -std=c++11 vs -std=c++14 so long as the same compiler flags were used with each case. This leads me to wonder if different compiler flags are used when selecting C++ 11. Perhaps a different optimization levels? Another possibility is that the difference could be in more at a system level. If your compilation / execution task is offloaded to a different set of resources depending on the selected C++ version, then either system load or hardware performance could be to blame.