Stream I/O performance

Source: Internet
Author: User

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 = 000000l;

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

In many compilers, stream I/O is 50% slower than C-style. If I/O is not yoursProgramIf the bottleneck occurs, ignore it. c ++ stream I/O uses time space for security.

 

PS: If your program TLE uses Cin, try scanf instead.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.