是否有一个好的Java库可以帮助您完成编写好的微基准测试的工作量?我正在考虑能够提供(尽量减少麻烦)提供文本(CSV或HTML,选择)输出结果的图表,以及总结结果的图表。理想情况下,它应该是与JUnit或等效的一起使用的东西,应该很容易配置带有可变参数的基准。
我看过japex,但发现它太重了( 25 MB 的图书馆要包含?!)而且坦率地说这只是一种痛苦。几乎不存在的文档,与ant,XML和路径混淆......等等。
答案 0 :(得分:4)
Google Collections团队中的一些人正在早期中构建满足您需求的东西。这是测量foo()占用时间的代码:
public class Benchmark1 extends SimpleBenchmark {
public void timeFoo(int reps) {
for (int i = 0; i < reps; i++) {
foo();
}
}
}
API和工具本身都不是特别稳定。我们甚至没有准备好接收错误报告或功能请求!如果我还没有吓到你,我邀请你带Caliper进行旋转。
答案 1 :(得分:1)
Oracle now has JMH. Not only is it written by members of the JIT team (who will take out much of the legwork of writing good micro-benchmarks), but it also has other neat features like pluggable profilers (including those that will print assembly of your hotspots with per-line cpu time).
It prints out tables. Not sure about graphs. The benchmarks can be configured with variable parameters. The documentation is fairly good.
It is easy to set up and get going. I've got it integrated with JUnit, but the developers provide a Maven archetype to get started.