Will my iPhone app take a performance hit if I use Objective-C for low level code?

后端 未结 8 2004
生来不讨喜
生来不讨喜 2020-12-04 07:57

When programming a CPU intensive or GPU intensive application on the iPhone or other portable hardware, you have to make wise algorithmic decisions to make your code fast.

8条回答
  •  余生分开走
    2020-12-04 08:15

    I have a couple of tests I did on an iPhone 3G almost 2 years ago, there was no documentation or hard numbers around in those days. Not sure how valid they still are but the source code is posted and attached.

    This isn't a very extensive test, I was mainly interested in NSArray vs C Array for iterating a large number of objects.

    http://memo.tv/nsarray_vs_c_array_performance_comparison

    http://memo.tv/nsarray_vs_c_array_performance_comparison_part_ii_makeobjectsperformselector

    You can see the C Array is much faster at high iterations. Since then I've realized that the bottleneck is probably not the iteration of the NSArray but the sending of the message. I wanted to try methodForSelector and calling the methods directly to see how big the difference would be but never got round to it. According to Mike Ash's benchmarks it's just over 5x faster.

提交回复
热议问题