Re: mach_absolute_time() vs. sleep() [solved]
Re: mach_absolute_time() vs. sleep() [solved]
- Subject: Re: mach_absolute_time() vs. sleep() [solved]
- From: Kristopher Matthews <email@hidden>
- Date: Wed, 30 Apr 2008 17:58:11 -0500
As "Ahruman" on freenode pointed out, it's faster to swap the original
divide and use a multiply at the end:
-(double)machElapsedTime:(uint64_t) start endTime: (uint64_t) endTime
{
uint64_t diff = endTime - start;
static double conversion = 0.0;
if (conversion == 0.0) {
mach_timebase_info_data_t info;
kern_return_t err = mach_timebase_info(&info);
if (err == 0)
conversion = info.denom / 1e9 * info.numer;
}
return diff * conversion;
}
(PS. That code is actually from http://macresearch.org/tutorial_performance_and_time
)
On Apr 30, 2008, at 5:52 PM, Kristopher Matthews wrote:
It was my fault. It turned out to be a pretty idiotic problem:
return conversion * (double) diff;
should be "return diff / conversion;"
Go go copying samples.
For completeness:
-(double)machElapsedTime:(uint64_t) start endTime: (uint64_t) endTime
{
uint64_t diff = endTime - start;
static double conversion = 0.0;
if (conversion == 0.0) {
mach_timebase_info_data_t info;
kern_return_t err = mach_timebase_info(&info);
if (err == 0)
conversion = 1e9 * info.numer / info.denom;
}
return diff / conversion;
}
On Apr 30, 2008, at 4:09 PM, Terry Lambert wrote:
Actually, it doesn't; the margin is just small enough that you
don't notice it.
Can you assure me that this is not for a homework assignment?
-- Terry
On Apr 30, 2008, at 1:34 PM, Kristopher Matthews wrote:
Care to elaborate? This code works fine in all circumstances where
sleep() is not called.
On Apr 30, 2008, at 3:30 PM, Terry Lambert wrote:
On Apr 30, 2008, at 4:13 AM, Kristopher Matthews wrote:
If you see my followup message, I wrote the sample code for this
email incorrectly. My apologies. :)
It should be:
double mach_elapsed_time(uint64_t start, uint64_t endTime)
{
You are doing a couple of really simple things wrong, but the
worst is being wrong about operator precedence order in C.
_______________________________________________
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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