Created
December 17, 2016 23:04
-
-
Save entzik/924f3731afb540c94d7079bd069d22b8 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
public class DoubleStreamAverageBenchmark { | |
@State(Scope.Thread) | |
public static class BenchmarkState { | |
public double[] values; | |
public BenchmarkState() { | |
values = new double[1000000]; | |
for (int i = 0; i < 1000000; i ++) | |
values[i] = Math.random(); | |
} | |
} | |
@Benchmark | |
@BenchmarkMode(Mode.All) | |
public void benchmark(BenchmarkState state, Blackhole bh) { | |
final OptionalDouble average = Arrays.stream(state.values).average(); | |
final double asDouble = average.getAsDouble(); | |
bh.consume(asDouble); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment