Last active
December 26, 2015 10:28
-
-
Save PrimaryFeather/7136635 to your computer and use it in GitHub Desktop.
Small benchmark code to test performance of Sparrow's "SPPoolObject".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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