这是我的第一个 JMH 基准测试。我可能做错了一切,但是......
我的基准看起来像这样
@State(Scope.Benchmark) public class JmhBranchingBenchmark {
private static final int STRING_LENGTH = 100 * 1000;
private char[][] allQueries = new char[101][];
@Setup public void up() {
for (int i=0; i<allQueries.length; ++i) {
... fill char[i] with STRING_LENGTH chars
... this might take some time, but it's needed only once, or?
}
}
@GenerateMicroBenchmark public void measure5(BlackHole bh) {
bh.consume(countBreakingWhitespace(allQueries[5]));
}
... some more nearly identical methods as a poor man's replacement for caliper's @Param
}
我开始了它……然后等了又等,然后杀死了它。我怀疑 中的问题@Setup
,所以我简化了它,但没有任何改变。跑步开始时非常乐观......
time -p java -jar target/microbenchmarks.jar ".*JmhBranchingBenchmark.*" -i 5 -f 1
# Run progress: 0.00% complete, ETA 00:02:05
# VM invoker: /usr/lib/jvm/java-7-oracle/jre/bin/java
# VM options: <none>
# Fork: 1 of 1
# Warmup: 20 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: org.openjdk.jmh.samples.JmhBranchingBenchmark.measure10
# Warmup Iteration 1:
然后什么也没有发生。很长一段时间后,它继续写20行,如
# Warmup Iteration 1: 6.415 ops/ms
和5行像
Iteration 1: 6.506 ops/ms
然后它输出一些结果
Result : 6.510 ±(99.9%) 0.030 ops/ms
Statistics: (min, avg, max) = (6.502, 6.510, 6.521), stdev = 0.008
Confidence interval (99.9%): [6.480, 6.540]
并更正其估计的 eta:
# Run progress: 20.00% complete, ETA 00:26:52
我是否@Setup
比我更频繁地被调用,或者还有什么可能是导致缓慢的原因?