I often hear the saying that iostream is inefficient in terms of performance, and it is better to use printf family if type-safe is not concern. But as far as I know, the static type checking (is this thing people call the 'type-safe' do?) is done in the compilation, and even the class mechanism (except virtual function) will not create a burden on run-time. Am I right? Or what exactly makes iostream inefficient?
Samuelandjw
0
Newbie Poster
Recommended Answers
Jump to Postiostream objects are usually slower than printf, but the little efficiency you gain by using printf is not worth avoiding the flexibility of the iostream classes.
(remember: iostream is not only cout, cin.)
Jump to PostThere are a lot of reasons to love iostream.
Standards don't say that iostream is slower or faster than stdio.
But usually iostream is build by wrapping stdio hence it is usually slower …
Jump to PostIt is said so, but could you tell me more about the technical details of why iostream is slower?
Can you be more detailed in what you mean with iostream ?
As I said in my previous post: it's a class library for I/O.
Maybe you meant cout versus printf …
Jump to Post, however I don't know whether you should take this seriously
Aah, then why not test it ourselfs?
#include <iostream> #include <cstdio> #include <windows.h> int main(){ long before = GetTickCount(); for (unsigned i = 0; i < 100000; i++) std::cout << "TEXT"; long coutstring = GetTickCount() - …
Jump to PostWe did all this less than a month ago.
http://www.daniweb.com/forums/thread198087.html
All 18 Replies
mvmalderen
2,072
Postaholic
Samuelandjw
0
Newbie Poster
siddhant3s
1,429
Practically a Posting Shark
mvmalderen
2,072
Postaholic
Samuelandjw
0
Newbie Poster
mvmalderen
2,072
Postaholic
Samuelandjw
0
Newbie Poster
mvmalderen
2,072
Postaholic
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
mvmalderen
commented:
Good point.
+12
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
mvmalderen
commented:
Good point :)
+12
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
mvmalderen
2,072
Postaholic
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
mvmalderen
2,072
Postaholic
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Salem
5,138
Posting Sage
Nick Evan
commented:
We didn't brag about our systemspecs in that thread :)
+21
mvmalderen
commented:
How could I forget :P
+12
MosaicFuneral
812
Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.