Created
June 21, 2016 15:26
-
-
Save isopov/916b525e4a7558ecb9053edf1f097362 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 characters
import java.util.concurrent.TimeUnit; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Fork; | |
import org.openjdk.jmh.annotations.Measurement; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.OutputTimeUnit; | |
import org.openjdk.jmh.annotations.Param; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.State; | |
import org.openjdk.jmh.annotations.Warmup; | |
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; | |
//Benchmark (power) Mode Cnt Score Error Units | |
//PowBenchmark2.cross 2 avgt 3 2.274 ± 0.112 ns/op | |
//PowBenchmark2.cross 3 avgt 3 3.516 ± 0.246 ns/op | |
//PowBenchmark2.cross 4 avgt 3 3.747 ± 0.066 ns/op | |
//PowBenchmark2.cross 5 avgt 3 5.275 ± 0.209 ns/op | |
//PowBenchmark2.cross 6 avgt 3 4.508 ± 0.205 ns/op | |
//PowBenchmark2.cross 7 avgt 3 4.824 ± 0.431 ns/op | |
//PowBenchmark2.cross 8 avgt 3 5.265 ± 2.930 ns/op | |
//PowBenchmark2.cross 9 avgt 3 5.758 ± 0.565 ns/op | |
//PowBenchmark2.cross 10 avgt 3 6.137 ± 0.174 ns/op | |
//PowBenchmark2.cross 15 avgt 3 8.908 ± 1.074 ns/op | |
//PowBenchmark2.cross 20 avgt 3 12.413 ± 1.586 ns/op | |
//PowBenchmark2.cross 50 avgt 3 37.568 ± 0.906 ns/op | |
//PowBenchmark2.pow 2 avgt 3 2.540 ± 0.657 ns/op | |
//PowBenchmark2.pow 3 avgt 3 62.126 ± 0.185 ns/op | |
//PowBenchmark2.pow 4 avgt 3 63.941 ± 0.204 ns/op | |
//PowBenchmark2.pow 5 avgt 3 63.942 ± 0.331 ns/op | |
//PowBenchmark2.pow 6 avgt 3 62.135 ± 0.106 ns/op | |
//PowBenchmark2.pow 7 avgt 3 63.955 ± 1.250 ns/op | |
//PowBenchmark2.pow 8 avgt 3 62.135 ± 0.263 ns/op | |
//PowBenchmark2.pow 9 avgt 3 62.465 ± 4.819 ns/op | |
//PowBenchmark2.pow 10 avgt 3 63.948 ± 1.227 ns/op | |
//PowBenchmark2.pow 15 avgt 3 62.430 ± 5.436 ns/op | |
//PowBenchmark2.pow 20 avgt 3 62.745 ± 1.034 ns/op | |
//PowBenchmark2.pow 50 avgt 3 63.900 ± 0.182 ns/op | |
@BenchmarkMode(Mode.AverageTime) | |
@Fork(1) | |
@State(Scope.Benchmark) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS) | |
@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) | |
public class PowBenchmark2 { | |
@Param({ "2", "3", "4", "5", "6", "7", "8", "9", "10", "15", "20", "50" }) | |
public int power; | |
private double i = Math.PI; | |
@Benchmark | |
public double cross() { | |
double result = i; | |
for (int i = 1; i < power; i++) { | |
result *= i; | |
} | |
return result; | |
} | |
@Benchmark | |
public double pow() { | |
return Math.pow(i, power); | |
} | |
public static void main(String[] args) throws RunnerException { | |
Options opt = new OptionsBuilder().include(".*" + PowBenchmark2.class.getSimpleName() + ".*") | |
.build(); | |
new Runner(opt).run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment