Skip to content

Instantly share code, notes, and snippets.

@sdpjswl
Last active August 29, 2015 14:20
Show Gist options
  • Save sdpjswl/59660453dee55120476d to your computer and use it in GitHub Desktop.
Save sdpjswl/59660453dee55120476d to your computer and use it in GitHub Desktop.
Handy macro to log method execution time
declare private function in 'libdispatch':
uint64_t dispatch_benchmark(size_t count, void (^block)(void));
and use it like so:
size_t const objectCount = 1000;
uint64_t n = dispatch_benchmark(10000, ^{
@autoreleasepool {
id obj = @42;
NSMutableArray *array = [NSMutableArray array];
for (size_t i = 0; i < objectCount; ++i) {
[array addObject:obj];
}
}
});
NSLog(@"-[NSMutableArray addObject:] : %llu ns", n);
Source:
http://www.objc.io/issue-2/low-level-concurrency-apis.html
-------------------
#define TICK NSDate *startTime = [NSDate date]
#define TOCK NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])
Source: http://stackoverflow.com/questions/2129794/how-to-log-a-methods-execution-time-exactly-in-milliseconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment