- Click to show recent forum activity -
Join our forums or log in.


What have you guys been working on?

What languages and projects have you guys been working on lately? I've mostly been doing web-related stuff (php/javascript/html/css) and some .NET. Played around with some Perl not too long ago and was thinking about get...

Project idea

Alright people ... let's start things up ... we have talented people around, we can do anything .. the thing i would like to do is a project that reaches alot of people and in different ways.. by that i mean web, Cross-p...

Should I add a hardware section?

Should I add a hardware section to the forums? I've been thinking about re-organizing the forums a bit and also seeing about getting some new moderators. Leave comments if you can and let me know. I'd like to get these f...

Getting started with .NET

If you didn't know, you can get a free version of Visual Studio 2008 -- Express Edition is what they call it. If you're interested in doing any kind of .NET programming I would highly recommend getting the free compiler ...

Related Posts

Spread the word

Digg this post

Bookmark to delicious

Stumble the post

Add to your technorati favourite

Subscribes to this post

5 users responded to this post

Quantumstate-Jim said in February 11th, 2009 at 12:03 pm    

I don’t get the same results. I first ran your executable to get the timings: 25, 20; 28, 27; 26, 25; 27, 28; 28, 27; So basically no difference there.

I then compiled my own using mingw to get the timings: 29, 26; 28, 26; 28, 24; 26, 29; 27,27; so no real differences here either. I also tried enabling the optimization flags but this had no effect.

The visual c++ compiler would not compile the code for me.

Reply

Daniel replied on

Interesting. I wonder if this is due to system specs? What kind of machine do you have? I’m running an Intel Core 2 Quad @ 2.66 ghz / 8 gb of ram with Vista x64. It could possibly be due to the OS as well?

Reply

Quantumstate-Jim replied on

I have a Pentium 4 Willamette processor (2.26Ghz) with 768Mb RAM and XP Home 32 bit.

Reply

Endian said in August 4th, 2009 at 4:21 pm    

To get the code to compile on windows just add .c_str() to testName[0] and testName[1].
I ran this on Windows Server 2008 R1 on Visual C++ 2008 SP2, and ended up with an average of 25ms for printf and 98ms for cout.

Reply

Carl said in August 23rd, 2009 at 9:54 am    

I think there are a few things missing from this test.

1A:
// Don’t be an english snob, make it international:ish.
_tsetlocale( LC_ALL, _T( “” ) );

1B:
and use some _non-english_ letters/characters in the test string ex “日本語” japanese

2:
// run on a single processor in order to get consistent results for all tests.
SetThreadAffinityMask( GetCurrentThread(), 1 );
SetThreadIdealProcessor( GetCurrentThread(), 0 );
Sleep( 1 );

3:
use QueryPerformanceCounter, etc.. not GetTickCount, ask google if you want to know why.

ok, this should make the test more correct.

Reply

Alpha Nox said in October 16th, 2009 at 8:46 pm    

Advising others to blindly use printf instead of the C++ std::cout is stupid.

If std::cout was the same as printf except slower then it wouldn’t have been included!

std::cout is a higher-level form of output and as such secure and extensible, e.g. you can overload the << operator.

Reply

Matthieu M said in May 20th, 2010 at 3:21 am    

I agree with Alpha Nox.

While printf may perform slightly better, I would remind you we are talking IO here which are anyway slower than most operations (even though buffering helps).

Furthermore, the 2 functions are wildly different: printf is completely unsecure and does not allow printing any non-precoded field (you can’t output your own class directly).

Finally, try Boost.Format. printf syntax with static type checking and positional arguments, ought to make your day ;)

Reply

Leave Your Comments Below

Currently you have JavaScript disabled. In order to post comments, please make sure JavaScript and Cookies are enabled, and reload the page. Click here for instructions on how to enable JavaScript in your browser.