package 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);
    }
}
