进行 TDD 时的性能测试最佳实践? [英] Performance testing best practices when doing TDD?

查看:15
本文介绍了进行 TDD 时的性能测试最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个急需进行性能调整的项目.

I'm working on a project which is in serious need of some performance tuning.

如果我的优化没有提高程序的速度,我该如何编写失败的测试?

How do I write a test that fails if my optimizations do not in improve the speed of the program?

稍微详细一点:

问题不在于发现要优化哪些部分.为此,我可以使用各种分析和基准测试工具.

The problem is not discovering which parts to optimize. I can use various profiling and benchmarking tools for that.

问题在于使用自动化测试来证明特定优化确实具有预期效果.如果我以后可以使用测试套件来发现可能的性能回归,那也是非常可取的.

The problem is using automated tests to document that a specific optimization did indeed have the intended effect. It would also be highly desirable if I could use the test suite to discover possible performance regressions later on.

我想我可以运行我的分析工具来获取一些值,然后断言我的优化代码会产生更好的值.然而,明显的问题是基准值不是硬值.它们因当地环境而异.

I suppose I could just run my profiling tools to get some values and then assert that my optimized code produces better values. The obvious problem with that, however, is that benchmarking values are not hard values. They vary with the local environment.

那么,总是使用同一台机器进行这种集成测试的答案是什么?如果是这样,您仍然必须考虑结果中的一些模糊性,因为即使在相同的硬件上,基准测试结果也可能会有所不同.那么如何考虑这一点呢?

So, is the answer to always use the same machine to do this kind of integration testing? If so, you would still have to allow for some fuzziness in the results, since even on the same hardware benchmarking results can vary. How then to take this into account?

或者答案可能是保留旧版本的程序并比较前后的结果?这将是我的首选方法,因为它主要与环境无关.有没有人有这种方法的经验?我想只有在最新版本的性能至少与旧版本一样好的情况下,如果所有测试都可以通过,则只需要保留一个旧版本.

Or maybe the answer is to keep older versions of the program and compare results before and after? This would be my preferred method, since it's mostly environment agnostic. Does anyone have experience with this approach? I imagine it would only be necessary to keep one older version if all the tests can be made to pass if the performance of the latest version is at least as good as the former version.

推荐答案

我怀疑应用 TDD 来提高性能是一个错误.无论如何,使用它来获得良好的设计和工作代码,并使用在 TDD 过程中编写的测试来确保持续的正确性 - 但是一旦你拥有良好的代码和一套可靠的测试,你就处于良好状态进行调优,并应用不同的(与 TDD 不同的)技术和工具.

I suspect that applying TDD to drive performance is a mistake. By all means, use it to get to good design and working code, and use the tests written in the course of TDD to ensure continued correctness - but once you have well-factored code and a solid suite of tests, you are in good shape to tune, and different (from TDD) techniques and tools apply.

TDD 为您提供良好的设计、可靠的代码和测试覆盖安全网.这会让你进入一个调整的好地方,但我认为由于你和其他人提到的问题,它不会让你在调整的道路上走得更远.作为 TDD 的忠实拥护者和支持者以及实践者,我这么说.

TDD gives you good design, reliable code, and a test coverage safety net. That puts you into a good place for tuning, but I think that because of the problems you and others have cited, it's simply not going to take you much further down the tuning road. I say that as a great fan and proponent of TDD and a practitioner.

这篇关于进行 TDD 时的性能测试最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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