微基准测试需要运行多长时间?
首先,这不是关于微基准测试的有用性。我很清楚他们的目的:在非常具体的情况下指示性能特征和比较,以突出一个方面。这是否会对你的工作产生任何影响则是另一回事了。
几年前,有人(我想是 Heinz Kabutz?)指出,每个值得花时间查看其结果的基准测试都必须运行至少几分钟,并且需要运行至少 3 次,而第一次运行是总是被丢弃。这是为了解释 JVM 的预热以及环境中的不一致(后台进程、网络流量……)和测量不准确。这对我来说很有意义,而且我的个人经历也暗示了类似的情况,所以我总是采用这种策略。
然而,我注意到很多人(例如 Jeff)编写仅运行几毫秒(!)并且仅运行一次的基准测试。我知道近年来短期运行基准的准确性有所提高,但我仍然觉得很奇怪。难道每个微基准测试不应该运行至少一秒并至少运行 3 次才能获得有用的输出吗?或者这个规则现在已经过时了吗?
First of all, this is not about the usefulness of microbenchmarks. I'm well aware of their purpose: Indicating performance characteristics and comparison in a very specific case to highlight a single aspect. Whether or not this should have any implications on your work is a different story.
A few years ago, someone (I think Heinz Kabutz?) noted that every benchmark that is worth the time to look at its results has to run at least a few minutes and needs to be run at least 3 times, whereas the first run is always discarded. That was to account for warming up the JVM as well as inconsistencies in the environment (background processes, network traffic, ...) and measurement inaccuracies. That made sense to me, and my personal experiences suggested something similar, so I always adopted this strategy.
However, I noticed many people (for instance Jeff) write benchmarks that only run for a couple milliseconds (!) and are run only once. I know that the accuracy of short-running benchmarks went up in the recent years, but it still strikes me as odd. Shouldn't every microbenchmark run for at least a second and be run at least 3 times to get a somewhat useful output? Or is that rule obsolete nowadays?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的经验,您需要:
我只倾向于使用计算密集型代码 - 如果您有不同的配置文件(例如内存密集型或大量 I/O),那么计时策略可能需要不同。
In my experience you need to:
I only tend to work with compute-intensive code - if you have a different profile (e.g. memory-intensive, or lots of I/O) then the timing strategy may need to be different.