如何执行良好的性能比较测试? [英] How do to perform a good performance comparations test?

查看:75
本文介绍了如何执行良好的性能比较测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要编写一个好的比较测试,您必须运行数千次.它将(在大多数情况下)提高其他程序的影响力.

但是JVM是否会影响结果.例如:

But if a JVM can influence on the results. For example:

第一个解决方案是:

    final StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(getStrOne());
    stringBuilder.append(getStrTwo());
    final String result1 = stringBuilder.toString();

第二个是:

    final String result2 = getStrOne() + getStrTwo();

我不知道哪个更好,因为JVM会影响结果.如何知道哪个更好?

I do not know which one is better because JVM can influence on the results. How to know which one is better?

更新:我并不是说 附加了比较测试.我问的是这样一种难以测试的情况.

UPDATE: I don't mean exactly that appending comporation test. I'm asking about such a hard to test situation.

推荐答案

我最近执行了一些基准测试,这些基准测试依赖于以下出色的IBM文章:

I recently performed some benchmark tests that relied on the excellent IBM article found here: http://www.ibm.com/developerworks/java/library/j-benchmark1/index.html.

本文介绍了许多可能影响结果准确性的陷阱,例如:

The article describes many of the pitfalls that can affect accuracy of results, for example:

  • 运行时优化/重新编译代码.
  • 消除无效代码(即未使用的结果可能会导致您的测试代码被删除)
  • 垃圾收集
  • 缓存
  • ...

最后,本文链接到可以下载的网站.该框架在完成测试方法,寻找重新编译的证据并等待执行时间确定方面做得非常好.

Finally, the article links to a site where a framework can be downloaded. The framework does a very good job of spooling up a test method, looking for evidence of recompilation and waiting for the execution time to settle.

这篇关于如何执行良好的性能比较测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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