Re: high accuracy timing options?
Re: high accuracy timing options?
- Subject: Re: high accuracy timing options?
- From: Steve Sisak <email@hidden>
- Date: Thu, 27 Mar 2008 16:42:31 -0400
At 3:14 PM -0400 3/27/08, Steve Sisak wrote:
Note this code is written in Eudora, not tested.
Here's a working version with numbers for a MacBook Pro 2.16GHz:
Still not sure what you're trying to do, but this is the same as your
code minus "back", which can't happen -- hope this tells you
something.
Since UpTime() just returns the processor timebase register, I'm
pretty sure it can't fail to increment.
Note that the absolute value of fiveSeconds is going to vary based on
processor architecture and speed.
--------
#include <CoreServices/CoreServices.h>
#include <sys/time.h>
#define NonZero(x) ((x).hi | (x).lo)
int
main(int argc, char *argv[])
{
u_int32_t count = 0, fail = 0, back = 0, i;
AbsoluteTime sleep_until, now, last, time_left;
AbsoluteTime fiveSeconds = DurationToAbsolute(5000 * kDurationMillisecond);
for (i = 0; i < 5; i ++) {
time_left = fiveSeconds; // make non-zero for fail case
sleep_until = AddAbsoluteToAbsolute(UpTime(), fiveSeconds);
last = UpTime();
do {
count++;
now = UpTime();
if ((now.lo == last.lo) && (now.hi == last.hi))
{
fail ++;
}
else
{
time_left = SubAbsoluteFromAbsolute(sleep_until, now);
}
last = now;
} while (NonZero(time_left));
printf("Ran UpTime() %lu times in 5 seconds.\n", count);
printf("%f UpTime()/usec\n", (float)count / 5000 / 1000);
printf("Failed to increment %lu times\n", fail);
printf("Back in time %lu times\n", back);
printf("-------------\n");
count = 0;
fail = 0;
back = 0;
}
exit(0);
}
Ran UpTime() 54272359 times in 5 seconds.
10.854471 UpTime()/usec
Failed to increment 0 times
Back in time 0 times
-------------
Ran UpTime() 54571267 times in 5 seconds.
10.914254 UpTime()/usec
Failed to increment 0 times
Back in time 0 times
-------------
Ran UpTime() 55075625 times in 5 seconds.
11.015125 UpTime()/usec
Failed to increment 0 times
Back in time 0 times
-------------
Ran UpTime() 55023597 times in 5 seconds.
11.004719 UpTime()/usec
Failed to increment 0 times
Back in time 0 times
-------------
Ran UpTime() 55205105 times in 5 seconds.
11.041020 UpTime()/usec
Failed to increment 0 times
Back in time 0 times
-------------
TimerTest has exited with status 0.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden