Quick Performance Measurements

A quick and easy way to measure the performance of a piece of iOS code is to dig down below all the Cocoa Touch stuff and use the low-level mach_absolute_time. This call returns a tick count that can be converted into nanoseconds using information obtained from the mach_timebase_info call. The following code sketches out the technique:

The timebase values on the simulator, at least on my MacBook Air, are 1/1, however on the iPad and iPhone 4 they are 125/3; so don’t be lazy and hard code them.

Never assume that because something runs quickly on the simulator it will also run quickly on a target device. On two jobs last year I encountered code that took 100x longer to run an iPad than in the simulator.

Apple Technical Q&A QA1398

About idz

A professional software engineer dabbling in iOS app development.
This entry was posted in Code Snippets and tagged , , , , . Bookmark the permalink.

One Response to Quick Performance Measurements

  1. Pingback: 检测一段iOS代码的执行效率函数 | 大专栏

Leave a Reply