943,794 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1359
  • C++ RSS
Sep 12th, 2008
0

Weird pthread performance difference with printf/cout

Expand Post »
Hi,

Trying to play with multithreading by taking some of my existing apps and converting them over. In doing so, I noticed a strange phenomenon that I've been able to reproduce in a very simple program.

let's say I create 2 threads. Each thread simply does a for loop from 1 to 1 billion and returns. The program on my (multi cpu) machine takes 2 - 3 seconds. However, if I put a single printf or cout in the thread's loop (let's say I check in the for loop if I'm at 500 million and if so execute the printf), then the same program takes over 25 seconds. This happens regardless of whether I put a mutex or not around the printf.

has anyone seen anything like this?

Winbatch
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Sep 12th, 2008
0

Re: Weird pthread performance difference with printf/cout

try the same thing in a single threded program and you will probably get the same or similar results.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Run time error in Copying substring dynamically
Next Thread in C++ Forum Timeline: C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC