Last active
December 1, 2017 19:02
-
-
Save chrisbrandow/9ea91880dd4b9c7aee53a6f31165b753 to your computer and use it in GitHub Desktop.
Objective-C dispatch Queue Speed Tests
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
- (void)testQueue { | |
dispatch_queue_t lockQueue = dispatch_queue_create("com.test.LockQueue", DISPATCH_QUEUE_SERIAL); | |
[self executeLockTest:^(VoidBlock block) { | |
dispatch_sync(lockQueue, ^{ | |
block(); | |
}); | |
}]; | |
} | |
- (void)disabled_testNoLock { | |
} | |
- (void)executeLockTest:(PerformBlock)performBlock { | |
NSInteger dispatchBlockCount = 16; | |
NSInteger iterationCountPerBlock = 100000; | |
// This is an example of a performance test case. | |
NSArray *queues = @[ | |
dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), | |
dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), | |
dispatch_get_global_queue(QOS_CLASS_UTILITY, 0) | |
]; | |
__block NSInteger value = 0; | |
[self measureBlock:^{ | |
dispatch_group_t group = dispatch_group_create(); | |
for(NSInteger block = 0; block < dispatchBlockCount; block++) { | |
dispatch_group_enter(group); | |
dispatch_queue_t queue = queues[block % queues.count]; | |
dispatch_async(queue, ^{ | |
for (NSInteger i = 0; i < iterationCountPerBlock; i++) { | |
performBlock(^(){ | |
value = value + 2; | |
value = value - 1; | |
}); | |
} | |
}); | |
} | |
}]; | |
//iphone 7 | |
//Objc | |
//'-[Test_Lock testQueue]' measured [Time, seconds] average: 0.000, relative standard deviation: 55.664%, values: [0.000048, 0.000015, 0.000014, 0.000013, 0.000024, 0.000013, 0.000018, 0.000014, 0.000014, 0.000013], performanceMetricID:com.apple.XCTPerformanceMetric_WallClockTime, baselineName: "", baselineAverage: , maxPercentRegression: 10.000%, maxPercentRelativeStandardDeviation: 10.000%, maxRegression: 0.100, maxStandardDeviation: 0.100 | |
//Swift (copied from: https://gist.github.com/steipete/36350a8a60693d440954b95ea6cbbafc) | |
//'-[Test_Lock_Speeds___SwiftTests.LockingTests testQueue]' measured [Time, seconds] average: 10.021, relative standard deviation: 9.422%, values: [10.429436, 11.166589, 10.586414, 10.119401, 8.534352, 8.205011, 10.162314, 11.007594, 10.547610, 9.448894], performanceMetricID:com.apple.XCTPerformanceMetric_WallClockTime, baselineName: "", baselineAverage: , maxPercentRegression: 10.000%, maxPercentRelativeStandardDeviation: 10.000%, maxRegression: 0.100, maxStandardDeviation: 0.100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment