Last active
October 12, 2023 09:58
-
-
Save dmhts/02947eec4ec1586ec167579bc7fcfde8 to your computer and use it in GitHub Desktop.
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
// - MARK: - Swift | |
let startTime = CACurrentMediaTime() | |
// Code to test | |
print("Runtime: \((CACurrentMediaTime() - startTime) * 1000) ms") | |
// MARK: - Obj-C | |
// Measuring runtime of the particular part of code | |
CFTimeInterval startTime = CACurrentMediaTime(); | |
// Code to test | |
NSLog(@"Runtime: %g ms", (CACurrentMediaTime() - startTime) * 1000); | |
// Measuring average runtime of isolated part of code | |
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); | |
uint64_t t = dispatch_benchmark(iterations, ^{ | |
@autoreleasepool { | |
// Code to test | |
} | |
}); | |
NSLog(@"Average Runtime: %llu ns", t); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment