这是我的第一个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]
并修正了其估计的埃塔:
# Run progress: 20.00% complete, ETA 00:26:52
我的@Setup
是否比我更频繁地被调用,或者是其他什么原因导致了这种缓慢?
发布于 2014-02-07 12:51:25
我想你是在对付非常重的@Setup
。
@Setup(Level.Trial)
在第一次使用@State
对象时会被延迟调用。这些初始化被计入执行时间,这也是进行热身的另一个很好的理由。因此,第一次热身过程中的第一次“打嗝”是@Setup
的执行。现在,JMH将在单独的VM中运行每个@GenerateMicroBenchmark
,因此下一个测试将经历相同的测试。
https://stackoverflow.com/questions/21618919
复制相似问题