diff --git a/multithreading1/src/main/java/cn/bunny/jmh/JMHExample09.java b/multithreading1/src/main/java/cn/bunny/jmh/JMHExample09.java new file mode 100644 index 0000000..6ca169c --- /dev/null +++ b/multithreading1/src/main/java/cn/bunny/jmh/JMHExample09.java @@ -0,0 +1,45 @@ +package cn.bunny.jmh; + +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@Fork(1) +@Warmup(iterations = 5) +@Measurement(iterations = 10) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Thread) +public class JMHExample09 { + + public static void main(String[] args) throws RunnerException { + Options options = new OptionsBuilder() + .include(JMHExample09.class.getSimpleName()) + .build(); + new Runner(options).run(); + } + + @Benchmark + public void baseline() { + } + + @Benchmark + public void measureLog1() { + double log = Math.log(Math.PI); + } + + @Benchmark + public void measureLog2() { + double log = Math.log(Math.PI); + double logged = Math.log(log); + } + + @Benchmark + public double measureLog3() { + return Math.log(Math.PI); + } +}