开发者

ctime on iOS device not measuring time properly

I need to calculate the time that a piece of my code takes to execute, right now I am using clock_t like so:

clock_t start = clock();

/* Do something here */

float executionTime = (clock()-(float)start) / CLOCKS_PER_SEC;

This works in the simulator, but when run on the device the value is always lower than what it should be. When running the simulator and my device at the same time the simulator finishes first but when my device finishes it has a shorter execution time.

The only difference between the simulator code and the device code is that开发者_JAVA技巧 a couple of functions are written in ARM assembly for the device.

In case this is relevant im using Xcode 4.1 and iOS 4.3.


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


It seems that after I rebooted my computer and my device clock() works again. Thanks to everyone that took the time to reply (:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜