Skip to content

Commit 1f028d3

Browse files
committed
Adding benchmark for histogram collector over point range query
1 parent 24d7323 commit 1f028d3

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/HistogramCollectorBenchmark.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import org.apache.lucene.sandbox.facet.plain.histograms.HistogramCollectorManager;
3434
import org.apache.lucene.search.IndexSearcher;
3535
import org.apache.lucene.search.MatchAllDocsQuery;
36+
import org.apache.lucene.search.PointRangeQuery;
3637
import org.apache.lucene.store.Directory;
3738
import org.apache.lucene.store.MMapDirectory;
39+
import org.apache.lucene.util.NumericUtils;
3840
import org.openjdk.jmh.annotations.Benchmark;
3941
import org.openjdk.jmh.annotations.BenchmarkMode;
4042
import org.openjdk.jmh.annotations.Fork;
@@ -122,9 +124,33 @@ public static class BenchmarkParams {
122124
}
123125

124126
@Benchmark
125-
public void collectHistogram(BenchmarkParams params) throws IOException {
127+
public void matchAllQueryHistogram(BenchmarkParams params) throws IOException {
126128
IndexSearcher searcher = new IndexSearcher(reader);
127129
searcher.search(
128130
new MatchAllDocsQuery(), new HistogramCollectorManager("f", params.bucketWidth, 10000));
129131
}
132+
133+
@Benchmark
134+
public void pointRangeQueryHistogram(BenchmarkParams params) throws IOException {
135+
IndexSearcher searcher = new IndexSearcher(reader);
136+
137+
Random r = new Random(0);
138+
int lowerBound = r.nextInt(params.docCount / 4, 3 * params.docCount / 4);
139+
// Filter for about 1/10 of the available documents
140+
int upperBound = lowerBound + params.docCount / 10;
141+
byte[] lowerPoint = new byte[Long.BYTES];
142+
byte[] upperPoint = new byte[Long.BYTES];
143+
NumericUtils.longToSortableBytes(lowerBound, lowerPoint, 0);
144+
NumericUtils.longToSortableBytes(upperBound, upperPoint, 0);
145+
final PointRangeQuery prq =
146+
new PointRangeQuery("f", lowerPoint, upperPoint, 1) {
147+
@Override
148+
protected String toString(int dimension, byte[] value) {
149+
return Long.toString(NumericUtils.sortableBytesToLong(value, 0));
150+
}
151+
};
152+
153+
// Don't need to increase the default bucket count
154+
searcher.search(prq, new HistogramCollectorManager("f", params.bucketWidth));
155+
}
130156
}

0 commit comments

Comments
 (0)