简体   繁体   中英

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 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 (:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM