Quantcast C++ time Text - Physics Forums Library

PDA

View Full Version : C++ time


ehrenfest
Jul25-08, 06:20 PM
I have been using the time.h header and the difftime function is good if you want to know the difference between two events measured in seconds but how do you get the difference between two events that occur milliseconds apart?

mgb_phys
Jul25-08, 06:24 PM
It depends on your operating system.
On windows QueryPerformanceCounter() will tell you the number of ticks since the last call, PerformanceCounterFrequency() tells you the frequency of the ticks ( it's about 10Mhz IIRC). Also take a look at 'multimedia timers'.

ehrenfest
Jul25-08, 06:44 PM
It depends on your operating system.
On windows QueryPerformanceCounter() will tell you the number of ticks since the last call, PerformanceCounterFrequency() tells you the frequency of the ticks ( it's about 10Mhz IIRC). Also take a look at 'multimedia timers'.

I am using Linux.

mgb_phys
Jul25-08, 10:03 PM
gettimeofday() contains microseconds since start of day,
I don't know what frequency it is updated at.
But if you google for QueryPerformanceCounter() alternatives under linux you should find something.

computerex
Jul28-08, 03:26 AM
gettimeofday() contains microseconds since start of day,
I don't know what frequency it is updated at.
But if you google for QueryPerformanceCounter() alternatives under linux you should find something.

Yes, gettimeofday is a good alternative. Function details here: http://www.linuxmanpages.com/man2/gettimeofday.2.php