I would like to know how long it's taking to send a message to an object with at least a 1ms accuracy. How do I do this?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
- XCode 4.5 giving me “SenTestingKit/SenTestKit.h” f
Use dispatch_benchmark to log method execution time in nanoseconds.
It has a much nicer syntax than manually looping and calling mach_absolute_time() dispatch_benchmark is part of Grand Central Dispatch. This function is not publicly declared, so you’ll have to do that yourself before use :
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void));
I am using this for log execution time :
Credit goes to Benchmarking
Here's what I do:
The output will be in seconds (with a decimal portion).
NSDate
s have resolution on the scale of milliseconds, although I'm not sure precisely how accurate they are.If the code you're trying to time is too fast, put it in a loop that runs the code a hundred times. (That assumes, of course, that the code you're timing has no side effects.)
You can use
mach_absolute_time
to measure in nanoseconds.Reference: Technical Q&A QA1398: Mach Absolute Time Units