4

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.

A Person
  • 801
  • 1
  • 10
  • 22
  • what value is lower than it should be? if the value is executionTime, it could be CLOCKS_PER_SEC which is off, which isn't unheard of. If it's start that is off, then you know it's clock(). – djhaskin987 Aug 15 '11 at 23:04
  • executionTime is lower than it should be on the device. If it is CLOCKS_PER_SEC that is off, is it possibly to fix it? – A Person Aug 15 '11 at 23:26

2 Answers2

1

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

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
0

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

A Person
  • 801
  • 1
  • 10
  • 22