Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add specialised andNotCardinality for improved performance (#378)
* add specialised andNotCardinality for improved performance * Remove unused import.
- Loading branch information
1 parent
7d0a686
commit 73a0957
Showing
4 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
jmh/src/jmh/java/org/roaringbitmap/combinedcardinality/CombinedCardinalityBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.roaringbitmap.combinedcardinality; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
import org.roaringbitmap.RandomData; | ||
import org.roaringbitmap.RoaringBitmap; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@Fork(value = 1, jvmArgsPrepend = | ||
{ | ||
"-XX:-TieredCompilation", | ||
"-XX:+UseParallelGC", | ||
"-mx2G", | ||
"-ms2G", | ||
"-XX:+AlwaysPreTouch" | ||
}) | ||
@State(Scope.Benchmark) | ||
public class CombinedCardinalityBenchmark { | ||
|
||
public enum Scenario { | ||
EQUAL { | ||
@Override | ||
RoaringBitmap[] bitmaps() { | ||
RoaringBitmap bitmap = RandomData.randomBitmap(1 << 12, 0.2, 0.3); | ||
return new RoaringBitmap[] {bitmap, bitmap.clone()}; | ||
} | ||
}, | ||
SHIFTED { | ||
@Override | ||
RoaringBitmap[] bitmaps() { | ||
RoaringBitmap bitmap = RandomData.randomBitmap(1 << 12, 0.2, 0.3); | ||
return new RoaringBitmap[] {bitmap, RoaringBitmap.addOffset(bitmap, 1 << 16)}; | ||
} | ||
}, | ||
SMALL_LARGE { | ||
@Override | ||
RoaringBitmap[] bitmaps() { | ||
return new RoaringBitmap[] { | ||
RandomData.randomBitmap(1 << 4, 0.2, 0.3), | ||
RandomData.randomBitmap(1 << 12, 0.2, 0.3) | ||
}; | ||
} | ||
}, | ||
LARGE_SMALL { | ||
@Override | ||
RoaringBitmap[] bitmaps() { | ||
return new RoaringBitmap[] { | ||
RandomData.randomBitmap(1 << 12, 0.2, 0.3), | ||
RandomData.randomBitmap(1 << 4, 0.2, 0.3) | ||
}; | ||
} | ||
} | ||
; | ||
abstract RoaringBitmap[] bitmaps(); | ||
} | ||
|
||
@Param | ||
Scenario scenario; | ||
|
||
RoaringBitmap left; | ||
RoaringBitmap right; | ||
|
||
@Setup(Level.Trial) | ||
public void init() { | ||
RoaringBitmap[] bitmaps = scenario.bitmaps(); | ||
left = bitmaps[0]; | ||
right = bitmaps[1]; | ||
} | ||
|
||
|
||
@Benchmark | ||
public int xorCardinality() { | ||
return RoaringBitmap.xorCardinality(left, right); | ||
} | ||
|
||
@Benchmark | ||
public int xorCardinalityBaseline() { | ||
return left.getCardinality() + right.getCardinality() - 2 * RoaringBitmap.andCardinality(left, right); | ||
} | ||
|
||
@Benchmark | ||
public int andNotCardinality() { | ||
return RoaringBitmap.andNotCardinality(left, right); | ||
} | ||
|
||
@Benchmark | ||
public int andNotCardinalityBaseline() { | ||
return left.getCardinality() - RoaringBitmap.andCardinality(left, right); | ||
} | ||
|
||
@Benchmark | ||
public int orCardinality() { | ||
return RoaringBitmap.orCardinality(left, right); | ||
} | ||
|
||
@Benchmark | ||
public int orCardinalityBaseline() { | ||
return left.getCardinality() + right.getCardinality() - RoaringBitmap.andCardinality(left, right); | ||
} | ||
} |