Created
November 15, 2011 20:56
-
-
Save groves/1368318 to your computer and use it in GitHub Desktop.
Revisions
-
groves created this gist
Nov 15, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ #import <mach/mach_time.h> void logMachTime_withIdentifier_(uint64_t machTime, NSString *identifier) { static double timeScaleSeconds = 0.0; if (timeScaleSeconds == 0.0) { mach_timebase_info_data_t timebaseInfo; if (mach_timebase_info(&timebaseInfo) == KERN_SUCCESS) { // returns scale factor for ns double timeScaleMicroSeconds = ((double) timebaseInfo.numer / (double) timebaseInfo.denom) / 1000; timeScaleSeconds = timeScaleMicroSeconds / 1000000; } } NSLog(@"%@: %g seconds", identifier, timeScaleSeconds*machTime); } // 0.46 seconds - (void)testPooledPoints { uint64_t startTime, stopTime; startTime = mach_absolute_time(); SPPoint *point = [[SPPoint alloc] initWithX:0.0 y:0.0]; for (int ii = 0; ii < 1000000; ii++) { float newX = point.x + 1; [point release]; point = [[SPPoint alloc] initWithX:newX y:0]; } stopTime = mach_absolute_time(); STAssertEquals(1000000.0f, point.x, @"X should've been incremented to 1000000, not '%f'", point.x); logMachTime_withIdentifier_(stopTime - startTime, @"10000000 pooled point instantiations"); } // 0.52 seconds - (void)testARCPoints { uint64_t startTime, stopTime; startTime = mach_absolute_time(); SPPoint *point = [[SPPoint alloc] initWithX:0.0 y:0.0]; for (int ii = 0; ii < 1000000; ii++) { float newX = point.x + 1; point = [[SPPoint alloc] initWithX:newX y:0]; } stopTime = mach_absolute_time(); STAssertEquals(1000000.0f, point.x, @"X should've been incremented to 1000000, not '%f'", point.x); logMachTime_withIdentifier_(stopTime - startTime, @"10000000 ARC point instantiations"); }