### absi2011's blog

By absi2011, history, 5 years ago,

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

• +9

 » 5 years ago, # |   0 Auto comment: topic has been updated by absi2011 (previous revision, new revision, compare).
 » 5 years ago, # | ← Rev. 3 →   0 I have done a "test" on that and it showed that if you gonna use cin for big input (even with ios::sync_with_stdio(0) and 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.
•  » » 5 years ago, # ^ | ← Rev. 3 →   +10 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.
•  » » » 5 years ago, # ^ |   +1 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.
•  » » » » 5 years ago, # ^ |   0 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.
•  » » » » » 5 years ago, # ^ |   -8 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.
•  » » » » » » 5 years ago, # ^ | ← Rev. 2 →   -18 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: std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); iostreams faster then stdio only on 32-bit integers.
•  » » » » » » » 5 years ago, # ^ |   +12 In other news, two people from top-2 on codeforces use cin / cout.
•  » » » » » » » 5 years ago, # ^ | ← Rev. 3 →   0 tourist uses cin/cout btw. but all of them use GNU C++14. And fateice uses scanf/printf also. I am glad to see the exact results if you can.
•  » » » » » » » » 5 years ago, # ^ |   0 GNU C++14 not a compiler, it's only flag -std=c++14 in 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?
•  » » » » » » » » » 5 years ago, # ^ |   0 Ralsei said "Ofcourse, specific compiler with different language versions is actually different compilers". And did I say that GNU C++14 is a compiler?
•  » » » » » » » » 5 years ago, # ^ |   0 I am glad to see the exact results if you can. I did it
 » 5 years ago, # | ← Rev. 7 →   0 Code for Input/Output 4.000.000 numbers with MinGW x64. MinGW Results----------- MinGW x64 8.1 - 4kk I/O speed test -------- ------------------------------------------------------- type | ifstream | scanf | ofstream | printf | ------------------------------------------------------- int | 1.311 | 1.435 | 1.474 | 1.818 | long long | 2.459 | 2.140 | 2.513 | 3.038 | double | 26.170 | 3.485 | 9.536 | 5.932 | ------------------------------------------------------- Code for Input/Output 4.000.000 numbers with Cygwin x64. Results: Cygwin Results---------- Cygwin x64 8.1 - 4kk I/O speed test -------- ------------------------------------------------------- type | ifstream | scanf | ofstream | printf | ------------------------------------------------------- int | 0.734 | 1.654 | 1.061 | 5.445 | long long | 1.388 | 2.792 | 1.528 | 8.689 | double | 6.521 | 1.965 | 58.110 | 77.953 | ------------------------------------------------------- UPD: Code for my first approach of implementation fast input / output classes using fread / fwrite Cygwin Results--- fread / fwrite - 4kk I/O speed test --- ------------------------------------------- type | fread | fwrite | ------------------------------------------- int | 0.275 | 0.630 | long long | 0.484 | 1.154 | double | 0.583 | 1.044 | ------------------------------------------- 
•  » » 5 years ago, # ^ |   +1 Why double is so slow with ofstream/printf but fast in fwrite?
•  » » » 5 years ago, # ^ | ← Rev. 2 →   0 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
 » 5 years ago, # |   0 The problem was using MS C++ in the first place.
 » 5 years ago, # |   0 So which compiler should i use to fasten my Code?