LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-24-2008, 12:25 PM   #1
torque_dwf
LQ Newbie
 
Registered: Aug 2005
Location: Upstate NY
Posts: 3

Rep: Reputation: 0
Can't get accurate time in MT program


Hi All, I am working on a multithreaded number crunching program and I am having a problem measuring elapsed time from particular steps that we report to the user as well as using for our own internal benchmarking. I seem to get the total time summed from all processors rather than real time used. We do not have this problem on windows.

i.e. time reported internal = 9 minutes
time reported by doing: time <program>
1 minute 30 seconds

can anyone give me a clue as to how I can measure time <in program>
and get real elapsed time rather than this total CPU time number?

I am using this code:
time1 = time( (time_t)0 );
{do some suff}
time2 = time( (time_t)0 );
elaped time = time2 - time1;

As far as I know this should work but I am not seeing it.

Any Ideas? Thanks,

Dan F.
 
Old 03-24-2008, 12:35 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by torque_dwf View Post
Hi All, I am working on a multithreaded number crunching program and I am having a problem measuring elapsed time from particular steps that we report to the user as well as using for our own internal benchmarking. I seem to get the total time summed from all processors rather than real time used. We do not have this problem on windows.

i.e. time reported internal = 9 minutes
time reported by doing: time <program>
1 minute 30 seconds

can anyone give me a clue as to how I can measure time <in program>
and get real elapsed time rather than this total CPU time number?

I am using this code:
time1 = time( (time_t)0 );
{do some suff}
time2 = time( (time_t)0 );
elaped time = time2 - time1;

As far as I know this should work but I am not seeing it.

Any Ideas? Thanks,

Dan F.
While I haven't tested it in a multi-threaded app, I check time by:
Code:
#include <time.h>
#include <stdio.h>
time_t start = clock();
// do some stuff
time_t end = clock();
printf(" Total build time: %.2fs\n",(float)(end - start)/(float)CLOCKS_PER_SEC);
of course you're have to do that in the thread itself rather than the calling function.

clock() is more granular than time(), though that doesn't explain the large discrepancy you posted.

edited to add: accoring to "man 3 clock", clock() actually returns a "clock_t" if you want to be very correct, though I'd bet that a clock_t and a time_t are both just uints. (also pardon my sloppy casting in the printf )

Last edited by BrianK; 03-24-2008 at 12:39 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ntpd not keeping time accurate humbletech99 Linux - Networking 2 05-22-2007 09:41 AM
I want to know the program execution time daggulasreedhar Programming 6 03-15-2007 04:07 AM
sound is mute & time is not accurate @ Unstable, 2.6 janus_tr Debian 3 08-25-2006 12:25 PM
System time not staying accurate sp|k3 Linux - General 10 01-02-2004 06:14 PM
How do I keep accurate time? teeno Linux - Software 8 10-11-2003 07:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration