http://www.glenmccl.com/perf_006.htm
Is stream I/O slower than C-style standard I/O? This question is a bit hard to answer. For a simple case like:
#ifdef CPPIO
#include <iostream.h>
#else
#include <stdio.h>
#endif
main()
{
long cnt = 1000000L;
while (cnt-- > 0)
#ifdef CPPIO
cout << 'x';
#else
putchar('x');
#endif
return 0;
}
the C++ stream I/O approach is about 50% slower for a couple of popular C++ compilers. But putchar() is a macro (equivalent to an inline function) that has been tuned, whereas the C++ functions in iostream.h are less tuned, and in the 50% slower case not all the internal little helper functions are actually inlined. We will say more about C++ function inlining some other time, but one of the issues with it is trading space for speed, that is, doing a lot of inlining can drive up code size.
And 50% may be irrelevant unless I/O is a bottleneck in your program in the first place
很多编译器上,stream I/O 比 C-style 慢了50%, 如果I/O 不是你的程序瓶颈的话, 忽略掉吧, C++ stream I/O用时间空间换来了安全性。
PS:如果你的程序TLE且使用了cin, 不妨换成scanf 试试