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 PostThere is no point comparing the difference because such a comparison will be compiler dependent. How one compiler implements cout and printf might be different than how some other compiler implements them. One compiler might wrap cout with printf() while another compiler might wrap cout with win32 api function WriteFile() …
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 PostVC++ 2008 Express on Vista Home Premium with 5 gig RAM 2 Mz CPU, quad core.
Debug build
cout string : 19562 ms
printf string : 6474 ms
cout int : 24368 ms
printf int : 6833 ms
Press any key to continue . . .Release build
cout …
Jump to PostAs you can see between posts #12 and #13 speed not only is compiler dependent but also machine dependent.
But I'm surprised to see that Code::Blocks using MinGW produces faster code than VC++ 2008.
Jump to PostWe did all this less than a month ago.
http://www.daniweb.com/forums/thread198087.html
All 18 Replies
tux4life 2,072 Postaholic
Samuelandjw 0 Newbie Poster
siddhant3s 1,429 Practically a Posting Shark
tux4life 2,072 Postaholic
Samuelandjw 0 Newbie Poster
tux4life 2,072 Postaholic
Samuelandjw 0 Newbie Poster
tux4life 2,072 Postaholic
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
tux4life commented: Good point. +12
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
tux4life commented: Good point :) +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
tux4life 2,072 Postaholic
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
tux4life 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,265 Posting Sage
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.