Add benchmarking for bitmaps

Here are the results on my laptop:

BitmapCreationBenchmark.testRandomAddition[0]: [measured 10 out of 20 rounds, threads: 1 (sequential)]
 round: 0.49 [+- 0.07], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 16, GC.time: 0.01, time.total: 9.91, time.warmup: 5.06, time.bench: 4.86
BitmapCreationBenchmark.testLinearAdditionDescending[0]: [measured 1000 out of 1010 rounds, threads: 1 (sequential)]
 round: 0.01 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 74, GC.time: 0.03, time.total: 5.82, time.warmup: 0.06, time.bench: 5.76
BitmapCreationBenchmark.testToImmutableByteArray[0]: [measured 1000 out of 1010 rounds, threads: 1 (sequential)]
 round: 0.00 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 0, GC.time: 0.00, time.total: 1.80, time.warmup: 0.02, time.bench: 1.78
BitmapCreationBenchmark.testRandomAddition[1]: [measured 10 out of 20 rounds, threads: 1 (sequential)]
 round: 0.00 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 0, GC.time: 0.00, time.total: 0.12, time.warmup: 0.08, time.bench: 0.04
BitmapCreationBenchmark.testLinearAdditionDescending[1]: [measured 1000 out of 1010 rounds, threads: 1 (sequential)]
 round: 0.00 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 10, GC.time: 0.01, time.total: 4.26, time.warmup: 0.04, time.bench: 4.22
BitmapCreationBenchmark.testToImmutableByteArray[1]: [measured 1000 out of 1010 rounds, threads: 1 (sequential)]
 round: 0.01 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 27, GC.time: 0.01, time.total: 5.11, time.warmup: 0.05, time.bench: 5.06
BitmapCreationBenchmark.testLinearAddition[0]: [measured 1000 out of 1010 rounds, threads: 1 (sequential)]
 round: 0.00 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 0, GC.time: 0.00, time.total: 3.48, time.warmup: 0.04, time.bench: 3.45
BitmapCreationBenchmark.testLinearAddition[1]: [measured 1000 out of 1010 rounds, threads: 1 (sequential)]
 round: 0.00 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 9, GC.time: 0.00, time.total: 2.95, time.warmup: 0.03, time.bench: 2.92
2014-11-13 12:47:23,995 INFO [main] io.druid.segment.data.BitmapCreationBenchmark - Entry [0] is io.druid.segment.data.ConciseBitmapSerdeFactory
2014-11-13 12:47:23,995 INFO [main] io.druid.segment.data.BitmapCreationBenchmark - Entry [1] is io.druid.segment.data.RoaringBitmapSerdeFactory
This commit is contained in:
Charles Allen 2014-11-13 12:48:04 -08:00
parent d4ca805cb9
commit 228fb0cf40
1 changed files with 144 additions and 0 deletions

View File

@ -0,0 +1,144 @@
package io.druid.segment.data;
import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.google.common.collect.ImmutableList;
import com.metamx.collections.bitmap.BitmapFactory;
import com.metamx.collections.bitmap.ImmutableBitmap;
import com.metamx.collections.bitmap.MutableBitmap;
import com.metamx.common.logger.Logger;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Random;
/**
*
*/
@RunWith(Parameterized.class)
public class BitmapCreationBenchmark extends AbstractBenchmark
{
private static final Logger log = new Logger(BitmapCreationBenchmark.class);
@Parameterized.Parameters
public static List<Class<? extends BitmapSerdeFactory>[]> factoryClasses()
{
return Arrays.<Class<? extends BitmapSerdeFactory>[]>asList(
(Class<? extends BitmapSerdeFactory>[]) Arrays.<Class<? extends BitmapSerdeFactory>>asList(
ConciseBitmapSerdeFactory.class
).toArray(),
(Class<? extends BitmapSerdeFactory>[]) Arrays.<Class<? extends BitmapSerdeFactory>>asList(
RoaringBitmapSerdeFactory.class
).toArray()
);
}
final BitmapFactory factory;
final ObjectStrategy<ImmutableBitmap> objectStrategy;
public BitmapCreationBenchmark(Class<? extends BitmapSerdeFactory> clazz)
throws IllegalAccessException, InstantiationException
{
BitmapSerdeFactory serdeFactory = clazz.newInstance();
factory = serdeFactory.getBitmapFactory();
objectStrategy = serdeFactory.getObjectStrategy();
}
private static final int numBits = 100000;
static Random random;
static int[] randIndex = new int[numBits];
@AfterClass
public static void cleanupAfterClass()
{
List<Class<? extends BitmapSerdeFactory>[]> classes = factoryClasses();
for (int i = 0; i < classes.size(); ++i) {
log.info("Entry [%d] is %s", i, classes.get(i)[0].getCanonicalName());
}
}
@BeforeClass
public static void setupBeforeClass()
{
for (int i = 0; i < numBits; ++i) {
randIndex[i] = i;
}
// Random seed chosen by hitting keyboard with BOTH hands... multiple times!
random = new Random(78591378);
for (int i = 0; i < numBits; ++i) {
int idex = random.nextInt(randIndex.length);
int swap = randIndex[i];
randIndex[i] = randIndex[idex];
randIndex[idex] = swap;
}
}
ImmutableBitmap baseImmutableBitmap;
MutableBitmap baseMutableBitmap;
byte[] baseBytes;
@Before
public void setup()
{
baseMutableBitmap = factory.makeEmptyMutableBitmap();
for (int i = 0; i < numBits; ++i) {
baseMutableBitmap.add(i);
}
baseImmutableBitmap = factory.makeImmutableBitmap(baseMutableBitmap);
baseBytes = baseImmutableBitmap.toBytes();
}
@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
@Test
public void testLinearAddition()
{
MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
for (int i = 0; i < numBits; ++i) {
mutableBitmap.add(i);
}
Assert.assertEquals(numBits, mutableBitmap.size());
}
@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 10)
@Test
public void testRandomAddition()
{
MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
for (int i : randIndex) {
mutableBitmap.add(i);
}
Assert.assertEquals(numBits, mutableBitmap.size());
}
@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
@Test
public void testLinearAdditionDescending()
{
MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
for (int i = numBits - 1; i >= 0; --i) {
mutableBitmap.add(i);
}
Assert.assertEquals(numBits, mutableBitmap.size());
}
@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
@Test
public void testToImmutableByteArray()
{
ImmutableBitmap immutableBitmap = factory.makeImmutableBitmap(baseMutableBitmap);
Assert.assertArrayEquals(baseBytes, immutableBitmap.toBytes());
}
}