显示最小、最大、平均……时间的秒表类?
我正在寻找一个模拟秒表的java类(例如 Spring 的 StopWatch 或 Commons' StopWatch),但这会给出最小、最大和平均时间。最好也对最后 n 次运行进行平均。
有这样的东西还是我自己构建它?
问候,
维姆
I am looking for a java class that simulates a StopWatch (like Spring's StopWatch or Commons' StopWatch) but that would give minimum, maximum and average times. Preferable also average over last n runs as well.
Is there such a thing or do I just build it myself?
regards,
Wim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该将这两个概念分开:
这两个概念实际上是非常不同的事情, IMO - 单独测试绝对比一起测试更容易。您很可能能够为每个单独的组件找到第三方库 - 或者可能使用现有的 StopWatch 类,但编写自己的统计分析器。
I think you should split up the two concepts:
The two are really pretty separate things, IMO - and definitely easier to test separately than together. You may well be able to find third party libraries for each separate component - or perhaps use an existing
StopWatch
class, but write your own stats cruncher.根据乔恩·斯基特的回答,这就是我想出的,以防其他人想要它。它使用 Spring 框架中的 StopWatch 类:
如果运行 stopWatch.prettyPrint(),它看起来像这样:
Following up to what Jon Skeet answered, this is what I have came up wiht in case somebody else wants it. It uses the StopWatch class from the Spring framework:
If you run
stopWatch.prettyPrint()
, it look like this: