iPhone 性能测量只运行一次的代码?
我想测量 iPhone 上只运行一次的代码的性能,因此 Instrument 的 CPU 采样器工具的用途有限,因为它需要多次迭代才能收集足够的样本。
是否有一个工具可以用来在每次调用时对每个函数进行计时?那确实调用跟踪而不是统计采样吗?
问候, 约亨
I'd like to measure the performance of code on the iPhone that runs only once, so Instrument's CPU sampler tool is of limited use, because it needs many iterations to collect enough samples.
Is there a tool that I can use that times each function on each invocation? That does call tracing instead of statistical sampling?
Regards,
Jochen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题“是否有非采样时间分析工具iPhone 应用程序?” 与您所问的类似。在我的回复中,我指出 DTrace,它可以进行基于函数调用的分析,但不幸的是只能在模拟器中工作,而不能在实际设备上工作。您还可以使用 Shark 以足够小的采样间隔收集数据。
最后,可以使用如下代码来对应用程序中的代码执行进行计时:
The question "Are there non-sampling time-profiling tools for iPhone apps?" is similar to what you're asking. In my response there, I point out DTrace, which can do function-call-based profiling, but unfortunately only works in the simulator, not on the actual device. You may also be able to gather data using Shark, with a small enough sampling interval.
Finally, code like the following can be used to do timing of code execution within your application:
如果您有一些大的代码块在被调用时执行不可接受,那么很可能其中包含一些耗时的循环,或者您调用了一些低效的低级函数。循环控制结构应该很容易通过检查来获取,并且通过手动计时 CGAbsoluteTimeGetCurrent() 和“二进制调试搜索”(是块的前半部分或中的瓶颈)来定位低效的低级函数通常非常容易第二季度还是第二季度?等等)
如果您无法找到此类搜索的热点,则很好地表明您在性能方面做得不错,并且要获得更好的性能,就需要重新思考您的方法。
我无意开玩笑,但你确定你在乎吗?如果代码只执行一次,那么它的相对性能可能只是出于好奇,而不是对最终用户有价值的东西。
If you have some large block of code that performs unacceptably the one time it is called, the odds are pretty good that it either has some time-consuming loops in it or you have some calls to inefficient lower-level functions. Looping control structures ought to be easy to pick up by inspection, and locating inefficient lower-level functions is generally pretty easy with hand-timing CGAbsoluteTimeGetCurrent() and a "binary debugging search" (is the bottleneck in the first half of the block or the second? First quarter or second quarter? etc.)
If you can't find a hotspot with that type of search, that's a pretty good indication that you're doing okay, performance-wise, and greater performance is going to require some kind of re-think of your approach.
I don't mean to be facetious, but are you sure you care? If the code only executes once, it's relative performance may be a matter of curiosity more than something of value to the end user.
可以通过插入来完成,这里是一篇介绍如何跟踪消息的文章,您也许可以在执行消息时调整它。
It could be done trough interposing, here is an article presenting how can it be done for tracing messages, you could perhaps adapt it at timing their execution.
Pulse 工程团队最近发表了一篇关于如何测量单行(或多行)Objective-c 代码性能的文章:http://eng.pulse.me/line-by-line-speed-analysis-for-ios-apps/
The Pulse engineering team recently published an article on how to measure the performance of single lines (or more) of Objective-c code: http://eng.pulse.me/line-by-line-speed-analysis-for-ios-apps/