1
這是我第一個JMH基準。我可能會做的一切錯誤的,但是....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
被調用的次數比我多得多,或者還有什麼可以成爲緩慢的原因?
你說得對。在詢問這裏之前,我進行了仔細檢查,但是這個複查是不夠的。 ;) – maaartinus