A Person
A Person

Reputation: 811

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.

Upvotes: 4

Views: 1070

Answers (2)

A Person
A Person

Reputation: 811

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

Upvotes: 0

Adam Rosenfield
Adam Rosenfield

Reputation: 400592

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

Upvotes: 1

Related Questions