Created
December 10, 2014 00:52
Revisions
-
ejain created this gist
Dec 10, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ package benchmark; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; @State(Scope.Thread) public class ArithmeticBenchmark { @Benchmark public long testDivide() { long value = Long.MAX_VALUE; while (value > 0) { value /= 2; } return value; } @Benchmark public long testShift() { long value = Long.MAX_VALUE; while (value > 0) { value = value >>> 1; } return value; } public static void main(String... args) throws Exception { Options opts = new OptionsBuilder() .include(ArithmeticBenchmark.class.getSimpleName()) .mode(Mode.Throughput) .warmupIterations(10) .measurementIterations(10) .jvmArgs("-server") .forks(1) .build(); new Runner(opts).run(); } } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Benchmark Mode Samples Score Error Units b.ArithmeticBenchmark.testDivide thrpt 10 3695399.946 ± 87327.372 ops/s b.ArithmeticBenchmark.testShift thrpt 10 8091063.504 ± 114824.341 ops/s