Skip to content

Instantly share code, notes, and snippets.

@entzik
Created December 17, 2016 23:04
Show Gist options
  • Save entzik/924f3731afb540c94d7079bd069d22b8 to your computer and use it in GitHub Desktop.
Save entzik/924f3731afb540c94d7079bd069d22b8 to your computer and use it in GitHub Desktop.
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