Quote:
Originally Posted by torque_dwf
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
)