XCode 6游乐场测量代码性能 [英] XCode 6 Playground Measuring Code Performance

查看:114
本文介绍了XCode 6游乐场测量代码性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有快速的方法来评估在新的XCode 6游乐场中编写的某个代码部分的性能/运行时间?

我想通过比较某些解决方案的不同编码样式及其对代码性能的影响来开始学习Swift。


Is there any quick way of evaluating the performance / runtime of a certain code part written in the new XCode 6 playground?
I want to start learning Swift by comparing different coding styles for certain solutions and their impact on the code performance.

推荐答案

我们强烈建议不要使用游乐场来衡量表现,至少要用时间作为衡量表现的方法。到目前为止,在操场上花费的大部分时间是记录结果显示在侧边栏中;您的代码所花费的实际时间并没有那么多。因此,操场中代码的运行时间主要取决于运行的代码行/结果的记录。

We strongly discourage using playgrounds to measure performance, at least using time as your measure of performance. By far the majority of the time taken during a playground is the logging of results to display in the sidebar; the actual time your code takes doesn't contribute as much. So the runtime of your code in a playground will mostly depend on how many lines of code are run / results are logged.

如果要进行性能测量,请查看XCTest框架。您可以为swift代码创建测试包。

If you want to do performance measurements, check out the XCTest framework. You can create a test bundle for your swift code.

您可以在游乐场中测量的一件事是您的代码行运行的次数。因此,例如,如果您尝试测量某些代码的算法复杂性,则可以根据运行代码行所需的次数来执行此操作。完成一种,或者你正在尝试做的任何事情。多次运行的代码行显示它们在结果侧栏中运行的次数。

One thing you can measure in a playground is the number of times your lines of code are run. So if, for example, you're trying to measure the algorithmic complexity of some code, you could do that based on how many times it needs to run lines of code to e.g. complete a sort, or whatever it is you're trying to do. Lines of code that are run more than once displays the number of times they are run in the results sidebar.

这篇关于XCode 6游乐场测量代码性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆