Ctime on iOS device does not measure time correctly

I need to calculate the time a piece of my code takes to execute, right now I'm using clock_t like this:

clock_t start = clock(); /* Do something here */ float executionTime = (clock()-(float)start) / CLOCKS_PER_SEC; 

This works in the simulator, but when launched on the device, the value is always less than it should be. When you start the simulator and my device at the same time, the simulator ends first, but when my device ends, it has a shorter runtime.

The only difference between the simulator code and the device code is that a couple of functions are written in the ARM assembly for the device.

In case it matters im using Xcode 4.1 and iOS 4.3.

+4
source share
2 answers

Have you tried using gettimeofday(2) or mach_absolute_time() instead?

+1
source

It seems that after restarting the computer and the device clock () is working again. Thanks to everyone who took the time to answer (:

0
source

All Articles