Precise Timing with mach_absolute_time()
Command-line tools are a great place to benchmark snippets of code, which is useful for those cases where you can isolate an algorithm or a programming technique out of your full application. A dozen-line or a couple-hundred-line command-line tool is a much more tractable problem than a million-line application. Not every problem can be put into a little benchmark, but enough of them can to make it a useful technique.
The nice thing about command-line programs is you can use the time command to get absolute figures of the running time of the program making it easy to compare and contrast changes you make to your target program.
But sometimes the time command does not have enough granularity. You might ...
Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.