Stream 1 - tuned, whereas the C++ functions in iostream.h...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Stream I/O Performance 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
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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....
View Full Document

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Ask a homework question - tutors are online