简体   繁体   English

使用仪器对性能进行基准测试

[英]Benchmarking performance using Instruments

I am looking for some advice on how to use Instruments' Time Profiler to enhance a specific operation. 我正在寻找有关如何使用仪器的Time Profiler来增强特定操作的一些建议。 I have a paging scroll view that loads its content on demand. 我有一个分页滚动视图,可以按需加载其内容。 As a new page is scrolled to, another is loaded two pages to the right. 当滚动到新页面时,另一个页面将向右加载两页。 This happens when the current page is scrolled 50% of screen, and on slower devices the loading is enough of a bottle neck that it interrupts the smoothness of the scroll. 当当前页面滚动50%的屏幕时会发生这种情况,而在较慢的设备上,加载足够瓶颈会中断滚动的平滑度。 The scroll feels like it pauses very briefly at the 50% pint and then jumps back into action. 滚动感觉就像它在50%品脱时非常短暂地暂停,然后跳回到行动中。

I should note that there is no network component to my application, so the bottle neck is not while data is fetched - it is all in the loading of the new view. 我应该注意到我的应用程序没有网络组件,因此在获取数据时瓶颈不是 - 它都在加载新视图。

As I work on improving this, I need to benchmark the transition so I can evaluate the effect of my enhancements. 当我努力改进这一点时,我需要对转换进行基准测试,以便我可以评估增强功能的效果。 Having watched the WWDC sessions, I understand the basics of the time profiler but I'm not confident I am looking at the right thing. 观看了WWDC会议后,我了解了时间分析器的基本知识,但我并不相信我正在寻找正确的事情。

I am running the instrument and then executing the scroll. 我正在运行仪器,然后执行滚动。 I see the expected spike in CPU activity. 我看到了CPU活动的预期峰值。 I am then selecting the spike and looking at the symbol names. 然后我选择尖峰并查看符号名称。 As you can see below, when I hide system libraries and show Obj-C I am dealing a brief 90% spike with 81.0 ms of running time. 正如您在下面看到的,当我隐藏系统库并显示Obj-C时,我正在处理一个短暂的90%尖峰,运行时间为81.0毫秒。

在此输入图像描述

My confusion comes when I drill down to my code. 当我深入到我的代码时,我的困惑就出现了。 I find that one of the largest contributors (23 ms) is a small routine that just uses sortedArrayUsingDescriptors . 我发现最大的贡献者之一(23毫秒)是一个只使用sortedArrayUsingDescriptors的小例程。 Not much I can do about that one. 我无能为力。 Other times the root cause will me using CGRectInset - a few more milliseconds. 其他时候根本原因是我使用CGRectInset - 几毫秒。 I guess I expected to see more related to image use or something like that. 我想我希望看到更多与图像使用或类似的东西有关。

I guess I don't know if I'm benchmarking the right things. 我想我不知道我是否正确对待正确的事情。 Am I really meant to try and reduce my 6ms operations down to 5ms and expect to see a difference? 我真的打算尝试将我的6ms操作减少到5ms并期望看到差异吗? Am I looking at the right tools to diagnose my problem? 我正在寻找合适的工具来诊断我的问题吗?

Any tips or instructions on what to measure and where to focus my efforts would be really valued. 关于衡量什么以及在哪里集中精力的任何提示或指示都将受到重视。

Consider using grand central dispatch to do as much non-UI work (fetching, sorting, selecting etc) as much as possible on a background thread. 考虑使用宏中央调度在后台线程上尽可能多地执行非UI工作(获取,排序,选择等)。 This will leverage the power of multi-cpu machines and get you off the main thread faster. 这将利用多CPU机器的强大功能,让您更快地离开主线程。 Only using main thread for ui work as needed. 仅根据需要使用主线程进行工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM