site_archiver@lists.apple.com Delivered-To: Darwin-dev@lists.apple.com double mach_elapsed_time(double start, double 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 = 1e-9 * (double) info.numer / (double) info.denom; } return conversion * (double) diff; } uint64_t s = mach_absolute_time(); NSLog(@"test"); double duration = mach_elapsed_time(s, mach_absolute_time()); uint64_t s = mach_absolute_time(); sleep(6); double duration = mach_elapsed_time(s, mach_absolute_time()); -- Terry _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On Apr 29, 2008, at 6:01 PM, Kristopher Matthews wrote: I'm having some strange trouble with these two calls. Example code follows. At this point, "duration" is a reasonable value in seconds. (About 0.005 IIRC.) This code also works for measuring another block of code I have that write several mbs to disk - the time it reports is in line with the difference between NSLog statements. But this: Produces completely unrealistic results - this specific example comes in at 0.387 seconds. Any thoughts? (I know, I know. this is a BS test case. I just happened upon it and I'm curious why this happens. I have no other problem with timing in this manner.) The type double and uint64_t are not the same type. A uint64_t is a 64 bit integer. Why are you dragging floating point into this without an explicit cast of the function arguments to doubles, and then expecting this to work? This email sent to site_archiver@lists.apple.com