简体   繁体   English

iOS 设备上的 ctime 无法正确测量时间

[英]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,如下所示:

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.模拟器代码和设备代码之间的唯一区别是,有几个函数是用 ARM 程序集为设备编写的。

In case this is relevant im using Xcode 4.1 and iOS 4.3.如果这是相关的,我使用 Xcode 4.1 和 iOS 4.3。

Have you tried using either gettimeofday(2) or mach_absolute_time() instead?您是否尝试过使用gettimeofday(2)mach_absolute_time()代替?

It seems that after I rebooted my computer and my device clock() works again.似乎在我重新启动计算机并且我的设备 clock() 再次工作后。 Thanks to everyone that took the time to reply (:感谢所有花时间回复的人(:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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