@TearDown(Level.Iteration) publicvoidcheck(){ assert x > Math.PI : "Nothing changed?"; }
@Benchmark publicvoidmeasureRight(){ x++; }
@Benchmark publicvoidmeasureWrong(){ double x = 0; x++; }
publicstaticvoidmain(String[] args)throws RunnerException { Options opt = new OptionsBuilder() .include(JMHSample_06_FixtureLevel.class.getSimpleName()) .warmupIterations(3) .measurementIterations(3) .forks(1) .jvmArgs("-ea") .shouldFailOnError(false) // switch to "true" to fail the complete run .build();
# Warmup: 3 iterations, 1 s each # Measurement: 3 iterations, 1 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Throughput, ops/time # Benchmark: JMH.JMHSample_06_FixtureLevel.measureRight
Result "measureRight": 399335988.728 ±(99.9%) 14286060.402 ops/s [Average] (min, avg, max) = (398754925.120, 399335988.728, 400226493.878), stdev = 783067.177 CI (99.9%): [385049928.326, 413622049.130] (assumes normal distribution)
# Warmup: 3 iterations, 1 s each # Measurement: 3 iterations, 1 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Throughput, ops/time # Benchmark: JMH.JMHSample_06_FixtureLevel.measureWrong
# Run progress: 50.00% complete, ETA 00:00:06 # Fork: 1 of 1 # Warmup Iteration 1: <failure>
java.lang.AssertionError: Nothing changed? at JMH.JMHSample_06_FixtureLevel.check(JMHSample_06_FixtureLevel.java:28) at JMH.generated.JMHSample_06_FixtureLevel_measureWrong_jmhTest.measureWrong_Throughput(JMHSample_06_FixtureLevel_measureWrong_jmhTest.java:80) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:430) at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:412) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
# Warmup: 3 iterations, 1 s each # Measurement: 3 iterations, 1 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op # Benchmark: JMH.JMHSample_07_FixtureLevelInvocation.measureCold
Result "measureCold": 77.290 ±(99.9%) 163.284 us/op [Average] (min, avg, max) = (70.264, 77.290, 87.367), stdev = 8.950 CI (99.9%): [≈ 0, 240.574] (assumes normal distribution)
# Warmup: 3 iterations, 1 s each # Measurement: 3 iterations, 1 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op # Benchmark: JMH.JMHSample_07_FixtureLevelInvocation.measureHot