Fastest I/O C++?

Which is the most fast and efficient method for input output in c++ for large chunks of data?
I know that the performance increases from cout cin to scanf printf,but I see people using much better methods here.If anyone could share one such method with a possible explanation to it,that would be great :smiley:

4 Likes

Actually,cin and cout can be faster than scanf() and printf(). But it depends.If you are not using scanf() and printf() ,then at the start of main() use std::ios_base::sync_with_stdio(false);.This turns off the intermixing calls to scanf()/printf() with operations on cin/cout. Actually,by default cin/cout wastes time synchronizing with c library’s stdio buffers.
for more info,just have a look on the link : interacting with C

But people use stuff like register char c = getche_unlocked() something something etc…in C,which method is that?Is there any explanation?Can I use it in C++?

I would like you to go through the following links:

  1. http://discuss.codechef.com/questions/11364/fast-io-discussion
  2. http://discuss.codechef.com/questions/356/what-is-this-fast-io-code-than-printf-scanf-in-c
  3. http://discuss.codechef.com/questions/11811/fast-io-discussion
  4. http://discuss.codechef.com/questions/7394/help-on-fast-inputoutput

Also you can look at some of the submissions of this question. The top solutions of this question uses good fast i/o functions.
I personally use this code for fast input output.

Excuse me brother,
http://digital-madness.in/blog/2013/fast-io-in-c/

I hope both are sufficient enough to quench your yearning.

5 Likes

It seems that, the difference by using std::ios_base::sync_with_stdio(false) is only observable if the input contains huge number of large integers, i.e. long or long long.

no page is working!

2 Likes