Skip to content

Instantly share code, notes, and snippets.

@dmhts
Last active October 12, 2023 09:58
Show Gist options
  • Save dmhts/02947eec4ec1586ec167579bc7fcfde8 to your computer and use it in GitHub Desktop.
Save dmhts/02947eec4ec1586ec167579bc7fcfde8 to your computer and use it in GitHub Desktop.
// - 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