通过 Objective C++ 强大功能提高 iPhone 程序的性能
2010-02-10 00:23:00 来源:WEB开发网核心提示:that's 194.756 ms per rectSpotsDB2 needed 3.0 seconds to count spots in 65 rectsthat's 46.450 ms per rectSpotsDB3 needed 3.0 seconds to count spots in 3
that's 194.756 ms per rect
SpotsDB2 needed 3.0 seconds to count spots in 65 rects
that's 46.450 ms per rect
SpotsDB3 needed 3.0 seconds to count spots in 3399 rects
that's 0.883 ms per rect
运行在Mac Pro之上的模拟器:
SpotsDB1 needed 3.0 seconds to count spots in 687 rects
that's 4.372 ms per rect
SpotsDB2 needed 3.0 seconds to count spots in 2687 rects
that's 1.117 ms per rect
SpotsDB3 needed 3.0 seconds to count spots in 187276 rects
that's 0.016 ms per rect
结论
观察结果我们可以看出在桌面电脑和iPhone上性能有显著的区别。有一个金科玉律是:在Mac上只需一秒的操作在iPhone上要一分钟。或者有一个更悲观的说法:Mac上60Hz的刷新率在iPhone上每秒钟只能更新一次。
所以显而易见在iPhone上进行优化是完全必须的。本文中我展示了几种方法来减小Object C的开销以及怎样使用C++来获得最大的性能。当然找到性能的瓶颈并转而使用数据结构使代码性能提升并不总是很容易的事情。但是在设计一个使用大量数据的程序时,绝对有必要考虑使用非Cocoa的方法。
[]
赞助商链接