Playing with JMH

When I tried to measure something with JMH, I created few methods which returned simple ints.

Like this:

@GenerateMicroBenchmark
public int return0() { return 0; }
@GenerateMicroBenchmark
public int return1() { return 1; }
@GenerateMicroBenchmark
public int return2() { return 2; }

And I was very (VERY) surprised with results.

Benchmark Mode Thr Count Sec Mean Mean error Units
t.SimpleReturns.return0 thrpt 1 100 1 339506,793 5390,430 ops/ms
t.SimpleReturns.return1 thrpt 1 100 1 744749,512 15169,150 ops/ms
t.SimpleReturns.return2 thrpt 1 100 1 503420,254 16123,554 ops/ms
API replied benchmark score: 339506.7927333333 ops/ms over 100 iterations
API replied benchmark score: 744749.5115 ops/ms over 100 iterations
API replied benchmark score: 503420.2544833333 ops/ms over 100 iterations

jdk1.8.0_25 on Windows 8.1 was used.

You just think about this, returning 1 is faster than return 0!

What about your test results?…

 Update: Seems this difference was here due to JMH 0.1 version, in latest (1.6) these methods runs roughly same time.