fivemack: (Default)
[personal profile] fivemack
At work, I've the good fortune of having a two-CPU workstation on my desk.

Unfortunately, whilst the two CPUs are within a centimetre of one another on the same piece of silicon, they appear to maintain independent clocks running with a noticeable offset; I can't tell if the speeds are also different.

In any case,

a = clock()
multi_threaded_operation()
b = clock()


can leave b reading out as several seconds before a, if the main thread was initially on the core with the later clock and got rescheduled onto the other one after the operation. This is not helpful for seeing which things are actually faster than which others.

Is there a standard C library routine, or at least something in <sys/*.h>, guaranteed to read a clock of a kind such that I can be reasonably confident that the computer's got only one?

Date: 2006-09-12 10:26 am (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com
clock() returns "an approximation of processor time used by the program". If you wanted something that was actually a time then try gettimeofday().

Date: 2006-09-12 10:44 am (UTC)
From: [identity profile] randwolf.livejournal.com
I think you want time(3) or gettimeofday(2); clock() is processor time, which differs for different threads. Also, beware of reentrance--you may be seeing a problem because you need to use an _r function somewhere. Better yet, use processes with shared memory regions, rather than threads.

Date: 2006-09-12 11:17 am (UTC)
sparrowsion: photo of male house sparrow (string-handling kitten)
From: [personal profile] sparrowsion
This reminded me of this recent thread on comp.lang.python—I'm not sure if the underlying problems are relevant to your case or not.

March 2024

S M T W T F S
     12
3456789
10111213141516
17181920212223
24 252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 6th, 2025 05:00 am
Powered by Dreamwidth Studios