views:

199

answers:

3

What is an easy way to time a Cocoa application? (Alternatively, any good way to measure performance would suffice).

(I have two different frameworks and would like to compare their performances over some fixed input data)

A: 

You can calculate the time of a cocoa app by using the NSTimer class. start the timer when the program runs and end it after all program logic has been completed.

zPesk
+8  A: 

Instruments will keep a clock for you, although you may find that the frameworks' difference is within the margin of how quickly you can start the app working on the data.

You can use Shark and the CHUD framework to do a better job of this. The framework lets you programmatically start and stop profiling; you'll start at the beginning of the work and end at the end of the work, and then have a nice Shark document to show for it. The Shark manual has more details.

Peter Hosey
A: 
NSDate *startDate = [NSDate date];
// ...
NSDate *stopDate = [NSDate date];

NSLog(@"-- time: %f", [stopDate timeIntervalSinceDate:startDate]);
nst