Skip to content

Instantly share code, notes, and snippets.

@junkdog
Last active August 16, 2016 10:49
Show Gist options
  • Save junkdog/fa28b1b9a8602090ddb717f1e3c9ce37 to your computer and use it in GitHub Desktop.
Save junkdog/fa28b1b9a8602090ddb717f1e3c9ce37 to your computer and use it in GitHub Desktop.
decoding bits to IntBag, benchmarking artemis-odb's BitVector
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 1, timeUnit = SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = SECONDS)
@Fork(1)
@Threads(1)
@State(Scope.Thread)
/*
# Run complete. Total time: 00:04:08
Benchmark (fillRate) Mode Cnt Score Error Units
BitsetBenchmark.bitset_foreach_intbag .01 thrpt 5 5046.399 ± 11.006 ops/ms
BitsetBenchmark.bitset_foreach_intbag .05 thrpt 5 1092.243 ± 5.624 ops/ms
BitsetBenchmark.bitset_foreach_intbag .10 thrpt 5 560.261 ± 5.282 ops/ms
BitsetBenchmark.bitset_foreach_intbag .20 thrpt 5 283.221 ± 1.861 ops/ms
BitsetBenchmark.bitset_foreach_intbag .40 thrpt 5 146.370 ± 3.111 ops/ms
BitsetBenchmark.bitset_foreach_intbag .50 thrpt 5 119.061 ± 2.943 ops/ms
BitsetBenchmark.bitset_foreach_intbag .60 thrpt 5 99.981 ± 1.434 ops/ms
BitsetBenchmark.bitset_foreach_intbag .70 thrpt 5 86.032 ± 1.212 ops/ms
BitsetBenchmark.bitset_foreach_intbag .80 thrpt 5 75.756 ± 0.637 ops/ms
BitsetBenchmark.bitset_foreach_intbag .95 thrpt 5 64.596 ± 0.288 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .01 thrpt 5 5994.359 ± 21.782 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .05 thrpt 5 1155.590 ± 12.800 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .10 thrpt 5 566.994 ± 4.478 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .20 thrpt 5 288.198 ± 2.673 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .40 thrpt 5 143.703 ± 1.528 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .50 thrpt 5 118.767 ± 1.382 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .60 thrpt 5 99.420 ± 1.374 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .70 thrpt 5 86.070 ± 0.488 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .80 thrpt 5 75.766 ± 0.775 ops/ms
BitsetBenchmark.bitvector_foreach_intbag .95 thrpt 5 65.070 ± 0.460 ops/ms
BitsetBenchmark.bitvector_to_intbag .01 thrpt 5 7011.413 ± 113.149 ops/ms
BitsetBenchmark.bitvector_to_intbag .05 thrpt 5 2383.966 ± 513.114 ops/ms
BitsetBenchmark.bitvector_to_intbag .10 thrpt 5 1642.287 ± 288.525 ops/ms
BitsetBenchmark.bitvector_to_intbag .20 thrpt 5 962.489 ± 162.995 ops/ms
BitsetBenchmark.bitvector_to_intbag .40 thrpt 5 615.183 ± 17.676 ops/ms
BitsetBenchmark.bitvector_to_intbag .50 thrpt 5 462.908 ± 4.134 ops/ms
BitsetBenchmark.bitvector_to_intbag .60 thrpt 5 427.239 ± 4.907 ops/ms
BitsetBenchmark.bitvector_to_intbag .70 thrpt 5 377.882 ± 1.142 ops/ms
BitsetBenchmark.bitvector_to_intbag .80 thrpt 5 332.062 ± 1.778 ops/ms
BitsetBenchmark.bitvector_to_intbag .95 thrpt 5 284.553 ± 5.138 ops/ms
*/
public class BitsetBenchmark {
private BitSet bitSet;
private BitVector bv;
@Param({".01", ".05", ".10", ".20", ".40", ".50", ".60", ".70", ".80", ".95"})
float fillRate;
int maxCount = 4096;
private IntBag ids = new IntBag();
@Setup
public void setup() {
bitSet = new BitSet();
bv = new BitVector();
Random rng = new Random(123456);
for (int i = 0; maxCount > i; i++) {
if (rng.nextFloat() <= fillRate) {
bitSet.set(i);
bv.set(i);
}
}
}
@Benchmark
public IntBag bitset_foreach_intbag() {
return ConverterUtil.toIntBag(bitSet, ids);
}
@Benchmark
public IntBag bitvector_to_intbag() {
return bv.toIntBag(ids);
}
@Benchmark
public IntBag bitvector_foreach_intbag() {
IntBag out = ids;
out.setSize(0);
if (bv.isEmpty()) {
return out;
}
for (int i = bv.nextSetBit(0); i >= 0; i = bv.nextSetBit(i + 1))
out.add(i);
return out;
}
public static void main(String[] args) throws RunnerException {
new Runner(
new OptionsBuilder()
.include(".*bit(set|vector).*")
.build()
).run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment