Skip to content

Commit

Permalink
Add benchmark for SortedRangeSet's getOrderedRanges
Browse files Browse the repository at this point in the history
Cherry-pick of trinodb/trino@2b5f7ff

Co-authored-by: Piotr Findeisen <[email protected]>
  • Loading branch information
zhenxiao and findepi committed May 18, 2021
1 parent 3faafe1 commit d887f69
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ private List<SortedRangeSet> benchmarkComplement(List<SortedRangeSet> dataRanges
return result;
}

@Benchmark
public List<Integer> getOrderedRangesSmall(Data data)
{
return benchmarkGetOrderedRanges(data.smallRanges);
}

@Benchmark
public List<Integer> getOrderedRangesLarge(Data data)
{
return benchmarkGetOrderedRanges(data.largeRanges);
}

private List<Integer> benchmarkGetOrderedRanges(List<SortedRangeSet> dataRanges)
{
List<Integer> result = new ArrayList<>(dataRanges.size());
for (int index = 0; index < dataRanges.size(); index++) {
int hash = 0;
for (Range orderedRange : dataRanges.get(index).getRanges().getOrderedRanges()) {
if (orderedRange.getLow().getValueBlock().isPresent()) {
hash = hash * 31 + orderedRange.getLow().getValue().hashCode();
}
if (orderedRange.getHigh().getValueBlock().isPresent()) {
hash = hash * 31 + orderedRange.getHigh().getValue().hashCode();
}
}
result.add(hash);
}
return result;
}

@State(Scope.Thread)
public static class Data
{
Expand Down

0 comments on commit d887f69

Please sign in to comment.