Skip to content

Commit af51b7c

Browse files
committed
Cleanup benchmarks
1 parent c63ba90 commit af51b7c

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/exponentialhistogram/ExponentialHistogramGenerationBench.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Random;
3333
import java.util.concurrent.ThreadLocalRandom;
3434
import java.util.concurrent.TimeUnit;
35+
import java.util.function.DoubleSupplier;
3536
import java.util.function.Supplier;
3637

3738
@BenchmarkMode(Mode.AverageTime)
@@ -54,36 +55,36 @@ public class ExponentialHistogramGenerationBench {
5455

5556
double[] data = new double[1000000];
5657

58+
int index;
59+
5760
@Setup
5861
public void setUp() {
5962
random = ThreadLocalRandom.current();
6063
histoGenerator = new ExponentialHistogramGenerator(bucketCount);
6164

62-
Supplier<Double> nextRandom = () -> distribution.equals("GAUSSIAN") ? random.nextGaussian() : random.nextDouble();
65+
DoubleSupplier nextRandom = () -> distribution.equals("GAUSSIAN") ? random.nextGaussian() : random.nextDouble();
6366

6467
// Make sure that we start with a non-empty histogram, as this distorts initial additions
6568
for (int i = 0; i < 10000; ++i) {
66-
histoGenerator.add(nextRandom.get());
69+
histoGenerator.add(nextRandom.getAsDouble());
6770
}
6871

6972
for (int i = 0; i < data.length; ++i) {
70-
data[i] = nextRandom.get();
73+
data[i] = nextRandom.getAsDouble();
7174
}
72-
}
7375

74-
@State(Scope.Thread)
75-
public static class ThreadState {
76-
int index = 0;
76+
index = 0;
7777
}
7878

79+
7980
@Benchmark
8081
@BenchmarkMode(Mode.AverageTime)
8182
@OutputTimeUnit(TimeUnit.MICROSECONDS)
82-
public void add(ThreadState state) {
83-
if (state.index >= data.length) {
84-
state.index = 0;
83+
public void add() {
84+
if (index >= data.length) {
85+
index = 0;
8586
}
86-
histoGenerator.add(data[state.index++]);
87+
histoGenerator.add(data[index++]);
8788
}
8889

8990
public static void main(String[] args) throws RunnerException {

benchmarks/src/main/java/org/elasticsearch/benchmark/exponentialhistogram/ExponentialHistogramMergeBench.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
@State(Scope.Thread)
4141
public class ExponentialHistogramMergeBench {
4242

43-
@Param({ "1000", "5000" })
43+
@Param({ "1000", "2000", "5000" })
4444
int bucketCount;
4545

4646
@Param({ "0.01", "0.1", "0.25", "0.5", "1.0", "2.0" })
@@ -51,6 +51,8 @@ public class ExponentialHistogramMergeBench {
5151

5252
ExponentialHistogram[] toMerge = new ExponentialHistogram[10_000];
5353

54+
int index;
55+
5456
@Setup
5557
public void setUp() {
5658
random = ThreadLocalRandom.current();
@@ -83,6 +85,8 @@ public void setUp() {
8385
throw new IllegalArgumentException("Expected bucket count to be " + dataPointSize + ", but was " + cnt);
8486
}
8587
}
88+
89+
index = 0;
8690
}
8791

8892
private static int getBucketCount(ExponentialHistogram histo) {
@@ -96,18 +100,13 @@ private static int getBucketCount(ExponentialHistogram histo) {
96100
return cnt;
97101
}
98102

99-
@State(Scope.Thread)
100-
public static class ThreadState {
101-
int index = 0;
102-
}
103-
104103
@Benchmark
105104
@BenchmarkMode(Mode.AverageTime)
106105
@OutputTimeUnit(TimeUnit.MICROSECONDS)
107-
public void add(ThreadState state) {
108-
if (state.index >= toMerge.length) {
109-
state.index = 0;
106+
public void add() {
107+
if (index >= toMerge.length) {
108+
index = 0;
110109
}
111-
histoMerger.add(toMerge[state.index++]);
110+
histoMerger.add(toMerge[index++]);
112111
}
113112
}

0 commit comments

Comments
 (0)