Skip to content

Instantly share code, notes, and snippets.

@Valloric
Created March 14, 2017 19:15
Show Gist options
  • Save Valloric/f57aa7726947250065dc1a878fc33888 to your computer and use it in GitHub Desktop.
Save Valloric/f57aa7726947250065dc1a878fc33888 to your computer and use it in GitHub Desktop.
@Fork(1)
@Threads(1)
@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 3)
@Measurement(iterations = 4, time = 3)
public class LockFreeBloomFilterBenchmark {
private static int NUM_BASE_PUTS = 1000000;
private static String TEST_URN = BenchmarkUtils.getRandomActivityUrn();
private LockFreeBloomFilter<String> _bloomFilter = LockFreeBloomFilter.create(
Funnels.unencodedCharsFunnel(),
150000000,
0.01,
LockFreeBloomFilterStrategies.MURMUR128_MITZ_32);
@Setup
public void setup() {
for (int i = 0; i < NUM_BASE_PUTS; i++) {
_bloomFilter.put(BenchmarkUtils.getRandomActivityUrn());
}
}
@Benchmark
public boolean measureContainSingleThread() {
return _bloomFilter.mightContain(TEST_URN);
}
@Benchmark
@Threads(4)
public boolean measureContainMultiThread() {
return _bloomFilter.mightContain(TEST_URN);
}
@Benchmark
public boolean measurePutSameSingle() {
return _bloomFilter.put(TEST_URN);
}
@State(Scope.Benchmark)
public static class InvocationState {
private static int NUM_RANDOM_URNS = 10000;
public String[] randomUrns = new String[NUM_RANDOM_URNS];
@Setup(Level.Invocation)
public void setup() {
for (int i = 0; i < NUM_RANDOM_URNS; i++) {
randomUrns[i] = BenchmarkUtils.getRandomActivityUrn();
}
}
}
@Benchmark
@Threads(1)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void measurePutBatchRandomsSingleThread(Blackhole blackhole,
InvocationState state) {
for (String urn : state.randomUrns) {
blackhole.consume(_bloomFilter.put(urn));
}
}
@Benchmark
@Threads(4)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void measurePutBatchRandomsMultiThread(Blackhole blackhole,
InvocationState state) {
for (String urn : state.randomUrns) {
blackhole.consume(_bloomFilter.put(urn));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment