spring
spring

Reputation: 18517

Timing how long a function takes

I've seen Q/A here about timing function duration in other languages but didn't find anything in Objective-C. If there is one, post the link and I will delete this question

I want to measure the time it takes for some functions to run. I've cobbled together the bits of code below but I wonder if there is a more compact or portable way to do this.

 CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();

 // do some work

 CFTimeInterval difference = CFAbsoluteTimeGetCurrent() - startTime;

 printf("elapsed:  %f\n", difference)

Upvotes: 0

Views: 540

Answers (2)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

If you want to precisely time very short timespans there are two additional timing facilities with very low overhead that come to my mind:

Upvotes: 3

One Man Crew
One Man Crew

Reputation: 9578

No,This is the best way using CFAbsoluteTimeGetCurrent(); its Absolute time is measured in seconds relative to the absolute reference date of Jan 1 2001 00:00:00 GMT

Upvotes: 3

Related Questions