|
12 | 12 | import org.apache.lucene.util.BytesRef; |
13 | 13 | import org.elasticsearch.common.io.stream.BytesStreamOutput; |
14 | 14 | import org.elasticsearch.exponentialhistogram.BucketIterator; |
| 15 | +import org.elasticsearch.exponentialhistogram.CompressedExponentialHistogram; |
15 | 16 | import org.elasticsearch.exponentialhistogram.ExponentialHistogram; |
16 | 17 | import org.elasticsearch.exponentialhistogram.ExponentialHistogramCircuitBreaker; |
17 | 18 | import org.elasticsearch.exponentialhistogram.ExponentialHistogramGenerator; |
18 | 19 | import org.elasticsearch.exponentialhistogram.ExponentialHistogramMerger; |
19 | | -import org.elasticsearch.xpack.analytics.mapper.IndexWithCount; |
20 | | -import org.elasticsearch.xpack.exponentialhistogram.CompressedExponentialHistogram; |
21 | 20 | import org.openjdk.jmh.annotations.Benchmark; |
22 | 21 | import org.openjdk.jmh.annotations.BenchmarkMode; |
23 | 22 | import org.openjdk.jmh.annotations.Fork; |
|
32 | 31 | import org.openjdk.jmh.annotations.Warmup; |
33 | 32 |
|
34 | 33 | import java.io.IOException; |
35 | | -import java.util.ArrayList; |
36 | 34 | import java.util.List; |
37 | 35 | import java.util.Random; |
38 | 36 | import java.util.concurrent.ThreadLocalRandom; |
@@ -109,28 +107,24 @@ public void setUp() { |
109 | 107 | } |
110 | 108 |
|
111 | 109 | private ExponentialHistogram asCompressedHistogram(ExponentialHistogram histogram) { |
112 | | - List<IndexWithCount> negativeBuckets = new ArrayList<>(); |
113 | | - List<IndexWithCount> positiveBuckets = new ArrayList<>(); |
114 | | - |
115 | | - BucketIterator it = histogram.negativeBuckets().iterator(); |
116 | | - while (it.hasNext()) { |
117 | | - negativeBuckets.add(new IndexWithCount(it.peekIndex(), it.peekCount())); |
118 | | - it.advance(); |
119 | | - } |
120 | | - it = histogram.positiveBuckets().iterator(); |
121 | | - while (it.hasNext()) { |
122 | | - positiveBuckets.add(new IndexWithCount(it.peekIndex(), it.peekCount())); |
123 | | - it.advance(); |
124 | | - } |
125 | | - |
126 | | - long totalCount = histogram.zeroBucket().count() + histogram.negativeBuckets().valueCount() + histogram.positiveBuckets() |
127 | | - .valueCount(); |
128 | 110 | BytesStreamOutput histoBytes = new BytesStreamOutput(); |
129 | 111 | try { |
130 | | - CompressedExponentialHistogram.writeHistogramBytes(histoBytes, histogram.scale(), negativeBuckets, positiveBuckets); |
| 112 | + CompressedExponentialHistogram.writeHistogramBytes( |
| 113 | + histoBytes, |
| 114 | + histogram.scale(), |
| 115 | + histogram.negativeBuckets().iterator(), |
| 116 | + histogram.positiveBuckets().iterator() |
| 117 | + ); |
131 | 118 | CompressedExponentialHistogram result = new CompressedExponentialHistogram(); |
132 | 119 | BytesRef data = histoBytes.bytes().toBytesRef(); |
133 | | - result.reset(histogram.zeroBucket().zeroThreshold(), totalCount, histogram.sum(), histogram.min(), histogram.max(), data); |
| 120 | + result.reset( |
| 121 | + histogram.zeroBucket().zeroThreshold(), |
| 122 | + histogram.valueCount(), |
| 123 | + histogram.sum(), |
| 124 | + histogram.min(), |
| 125 | + histogram.max(), |
| 126 | + data |
| 127 | + ); |
134 | 128 | return result; |
135 | 129 | } catch (IOException e) { |
136 | 130 | throw new RuntimeException(e); |
|
0 commit comments