If you're really lazy you can download the code for SimpleProfile and as a bonus an example profile framework SimpleProfileFramework (some modification of SimpleProfile required).
The code on the right side will be the test code to be used for the following demonstration. Apart from some niceties for sampling - the NSRunAlertPanel and sleep calls - the -[Controller awakeFromNib] method does nothing more than call the methods -[Controller foo] and -[Controller bar] repeatedly. Both methods do an equal amount of memcpy calls, -[Controller foo] copying 5120000 bytes and -[Controller bar] copying 2560000 bytes.
An instance of Controller is embedded in the NIB file, that is loaded when the application starts up. The load of the NIB file in turn triggers the -[Controller awakeFromNib] messages.
Two simple predictions
- -[Controller foo] will be slower than -[Controller bar], because -[Controller foo] has to do more work
- most of the time will be spent in the memcpy routine, because looping and function calling should be relatively inexpensive

Sampler.app
|
Now it is time to launch the profiler called Sampler.app, which you should be able to locate in /System/Developer/Applications or some such path.
|
When the profiling windows opens (see below) Set Executable to your applications "profile binary" and ensure that Arguments reads -NSUseRunningCopy NO (red arrow).
After that just press Launch and Sample. When you think you have collected enough data, press Stop Sampling and examine the output in the browser views. You can press Stop Sampling at any time, because your application running and Sampler.app are two different processes. You can also launch the application first without sampling and start sampling when its most convenient and meaningful (yellow).
|
@implementation Controller
static char dst[ 512];
static char src[ 512];
#define LOOPS 10000
- (void) foo
{
unsigned int i;
for( i = 0; i < LOOPS; i++)
memcpy( dst, src, sizeof( dst));
}
- (void) bar
{
unsigned int i;
for( i = 0; i < LOOPS; i++)
memcpy( dst, src, sizeof( dst) / 2);
}
- (void) awakeFromNib
{
unsigned int i;
NSRunAlertPanel( @"START", @"When you press \
OK there will be a 3 seconds delay, then a beep \
will be heard and the test will run.\nStart \
sampling at that moment.\nPress Stop sampling \
when you hear the second beep (or preferrably a \
bit earlier :))\n", @"OK", nil, nil);
sleep( 3);
NSBeep();
for( i = 0; i < 1000; i++)
{
[self foo];
[self bar];
}
NSBeep();
sleep( 1);
NSRunAlertPanel( @"END", @"The test is thru \
", @"OK", nil, nil);
}
@end
|