feat: JMHExample11

This commit is contained in:
Bunny 2025-01-19 15:37:09 +08:00
parent 922393d2d9
commit 78ff512f26
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
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 JMHExample11 {
private final double x1 = 124.56;
private final double x2 = 342.456;
private final double y1 = 124.56;
private final double y2 = 342.456;
public static void main(String[] args) throws RunnerException {
final Options options = new OptionsBuilder()
.include(JMHExample11.class.getSimpleName())
.build();
new Runner(options).run();
}
@Benchmark
public double returnDirect() {
return 42_620.703936d;
}
@Benchmark
public double returnDirect2() {
return x1 * x2;
}
@Benchmark
public double returnCac_2() {
return Math.log(y1) * Math.log(y2);
}
@Benchmark
public double returnCac_3() {
return Math.log(x1) * Math.log(x2);
}
}