cin vs scanf, which one is faster?

6

In competitive programming, it is common for many programmers to use scanf() and printf() in C ++ code instead of using cin and cout .

And I've even seen problems that result in a Time Limit Exceeded (TLE) when used cin and cout , but run within time when scanf() is used printf() , implementing the same idea in the algorithms.

Then there is the question, scanf() is always faster than cin , will it depend on the case or cin is faster?

    
asked by anonymous 01.05.2016 / 22:47

1 answer

7

Because performance may vary by implementation, those who will do competitive programming will certainly test this on the implementation used to make sure which is best. If the person does not know that this is the correct way, it is better not to compete.

In a good compiler (standard library), without bugs , well written, if you use std::ios_base::sync_with_stdio(false) and do not do any nonsense in thesis is to be basically the same performance. It will hardly be the same, after all they are different implementations.

Contrary to popular belief, it has a reasonable chance of C ++

01.05.2016 / 23:06