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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.