Skip to content

Instantly share code, notes, and snippets.

@PrimaryFeather
Last active December 26, 2015 10:28
Show Gist options
  • Save PrimaryFeather/7136635 to your computer and use it in GitHub Desktop.
Save PrimaryFeather/7136635 to your computer and use it in GitHub Desktop.
Small benchmark code to test performance of Sparrow's "SPPoolObject".
#import <QuartzCore/QuartzCore.h> // for CACurrentMediaTime()
- (void)runPoolBenchmark
{
double startTime, endTime;
const int NumObjects = 1000000;
typedef SPMatrix SPObject;
[SPObject purgePool];
NSMutableArray *array = [NSMutableArray arrayWithCapacity:NumObjects];
NSLog(@"Filling pool with %d objects ...", NumObjects);
@autoreleasepool
{
for (int i=0; i<NumObjects; ++i)
array[i] = [[SPObject alloc] init];
[array removeAllObjects];
}
NSLog(@"Starting pool test ...");
@autoreleasepool
{
startTime = CACurrentMediaTime();
for (int i=0; i<NumObjects; ++i)
array[i] = [[SPObject alloc] init];
endTime = CACurrentMediaTime();
[array removeAllObjects];
}
double duration = endTime - startTime;
NSLog(@"Created %d objects in %.5f seconds", NumObjects, duration);
NSLog(@"(That's %d objects per second)", (int)(NumObjects / duration));
int poolSize = [SPObject purgePool];
NSLog(@"Purged pool, contained %d objects", poolSize);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment