I used cin and got TLE in Feb 15th.
Then I test the scanf and got Accepted.
I found it interesting that different C++ get different verdict with cin.
Several times of MS C++ because I found interesting of it TLE on different test.
My Submissions on 932D - Tree with submissions 40405924 (Code is same, Language is different)
MS C++ Time limit exceeded on test 80
GNU C++17 Accepted 1356 ms
GNU C++14 Accepted 1326 ms
GNU C++11 Time limit exceeded on test 81
GNU C++ Accepted 1902 ms
GNU C++17 Diagnostics Time limit exceeded on test 11
MS C++ Time limit exceeded on test 81
MS C++(scanf) Accepted 421 ms
MS C++(Submit on Feb 15th) Time limit exceeded on test 82
Auto comment: topic has been updated by absi2011 (previous revision, new revision, compare).
I have done a "test" on that and it showed that if you gonna use
cinfor big input (even with
cin.tie(0)) C++ 17 and C++14 will give better results than C++11 and C++ "on some conditions". Although I don't know the reason behind that. And I got downvotes when I made a blog about it.
I don't understand why people thinks that things like speed of some functions depends on C++ language version, while it actually should depend on compiler used. Ofcourse, specific compiler with different language versions is actually different compilers, but it has nothing to do with "C++17 gives better results" — maybe, only for this specific compiler, so results on your computer and on CF differs a lot.
Also, different IO gives different results on different types of input/output data, so "research" on one specific test is actually useless.
1#: I actually did that on Codeforces. Not in my device.
2#: I did it with integers which is the most common data type in problems. I will try the same with strings later.
What about many small numbers? Or less, but bigger numbers? Or mixed data? Or boolean data? What about reading int versus reading long long. What about non-integer numbers? "Research" called "research" for a reason.
Also, I was talking generally, not about CF. And it seems pointless to me to test such things on CF, cause it's such a rare case when IO speed actually matters here. cin/cout never failed me.
I am actually cin/cout user. And it did not fail me neither. But absi2011 has a point to discuss. You can call what I did what you want. I did very small "test" which is reading 200000 positive and negative integers about between -1e9 and 1e9. C++17 and C++14 were two times faster than C++11 and C++. And we are here in Codeforces. I don't personally care if another online judge gives different results. My test was about Codeforces and not anything else. And you are absolutely right about the point of different input types. What I did was the most common input type from my experience so far. You can analyze the results as you want. (which is better than me). Saying that the test was useless is not helping anybody here.
By the way, three people from top-5 on codeforces use
scanf / printf: Um_nik, amiya, Syloviaely.
I tested input / output (int, long long, double, strings) on MinGW 8.1 (enabled on codeforces) with:
iostreams faster then stdio only on 32-bit integers.
In other news, two people from top-2 on codeforces use
cin / cout.
tourist uses cin/cout btw. but all of them use GNU C++14. And fateice uses
scanf/printfalso. I am glad to see the exact results if you can.
GNU C++14 not a compiler, it's only flag
-std=c++14in compiler command, maybe something else. The speed of input is influenced by the program code of the compiler, it is different for each compiler, but the behavior of the code is subject to the standard. What is faster on windows with I/O: cygwin or mingw? Scanf/printf, iostreams in cygwin, or scanf/printf, iostreams in mingw?
Ralsei said "Ofcourse, specific compiler with different language versions is actually different compilers". And did I say that GNU C++14 is a compiler?
I did it
Code for Input/Output 4.000.000 numbers with MinGW x64.
Code for Input/Output 4.000.000 numbers with Cygwin x64. Results:
UPD: Code for my first approach of implementation fast input / output classes using fread / fwrite
Why double is so slow with ofstream/printf but fast in fwrite?
Compiler developers develop stable, thread-safe I / O, they are limited by the standard, plus they must consider the exponential form too. I have not looked at the source code in the compilers, but I think that they call too many template functions to provide the above guarantees to the user. Here I wrote my own input / output function for double and it's fast, maybe someone can input / output double faster. I know that MikeMirzayanov or his team have own input / output library for checkers on github
The problem was using MS C++ in the first place.
So which compiler should i use to fasten my Code?