Skip to content

Commit 9f0be8e

Browse files
jmh module
1 parent 97e9d65 commit 9f0be8e

File tree

6 files changed

+158
-1
lines changed

6 files changed

+158
-1
lines changed

fastfilter/src/main/java/org/fastfilter/bloom/count/SuccinctCountingBlockedBloomRanked.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public long getBitCount() {
6363
this.seed = Hash.randomSeed();
6464
long bits = (long) entryCount * bitsPerKey;
6565
this.buckets = (int) bits / 64;
66-
int arrayLength = (int) (buckets + 16);
66+
int arrayLength = buckets + 16;
6767
data = new long[arrayLength];
6868
counts = new long[arrayLength];
6969
overflow = new long[100 + arrayLength * 10 / 100];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.fastfilter;
2+
3+
4+
import org.openjdk.jmh.annotations.Benchmark;
5+
import org.openjdk.jmh.annotations.OutputTimeUnit;
6+
7+
import java.util.concurrent.TimeUnit;
8+
9+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
10+
public class ConstructionBenchmark {
11+
12+
@Benchmark
13+
public Filter construct(FilterConstructionState state) {
14+
return state.getConstructor().construct(state.getKeys(), 64);
15+
}
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.fastfilter;
2+
3+
public class Environment {
4+
public static int SEED = Integer.parseInt(System.getProperty("org.fastfilter.seed", "0"));
5+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.fastfilter;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Benchmark)
6+
public class FilterConstructionState {
7+
8+
@Param({"1048576", "2097152"})
9+
int size;
10+
11+
@Param({"RANDOM32", "RANDOM64"})
12+
KeyGenerationStrategy kgs;
13+
14+
@Param({"BLOOM",
15+
"COUNTING_BLOOM",
16+
"SUCCINCT_COUNTING_BLOOM",
17+
"SUCCINCT_COUNTING_BLOOM_RANKED",
18+
"BLOCKED_BLOOM",
19+
"SUCCINCT_COUNTING_BLOCKED_BLOOM",
20+
"SUCCINCT_COUNTING_BLOCKED_BLOOM_RANKED",
21+
"XOR_SIMPLE",
22+
"XOR_SIMPLE_2",
23+
"XOR_8",
24+
"XOR_16",
25+
"XOR_PLUS_8",
26+
"CUCKOO_8",
27+
"CUCKOO_16",
28+
"CUCKOO_PLUS_8",
29+
"CUCKOO_PLUS_16",
30+
"GCS",
31+
"GCS2",
32+
"MPHF"})
33+
FilterType type;
34+
35+
long[] keys;
36+
37+
public long[] getKeys() {
38+
return keys;
39+
}
40+
41+
public FilterType getConstructor() {
42+
return type;
43+
}
44+
45+
@Setup(Level.Trial)
46+
public void init() {
47+
this.keys = new long[size];
48+
kgs.fill(keys);
49+
}
50+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.fastfilter;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Benchmark)
6+
public class FilterQueryState extends FilterConstructionState {
7+
8+
@AuxCounters
9+
static class Counters {
10+
private final long bitCount;
11+
int workDone;
12+
int found;
13+
int notFound;
14+
15+
Counters(Filter filter) {
16+
this.bitCount = filter.getBitCount();
17+
}
18+
}
19+
20+
@Param({"10", "15", "20", "25"})
21+
int logDistinctLookups;
22+
23+
@Param({"0.1", "0.5", "0.9"})
24+
float trueMatchProbability;
25+
26+
private long[] keysToFind;
27+
private Counters counters;
28+
29+
public void found() {
30+
++counters.found;
31+
}
32+
33+
public void notFound() {
34+
++counters.notFound;
35+
}
36+
37+
Filter filter;
38+
39+
public Filter getFilter() {
40+
return filter;
41+
}
42+
43+
public long nextKey() {
44+
return keysToFind[(counters.workDone++) & (keysToFind.length - 1)];
45+
}
46+
47+
@Override
48+
@Setup(Level.Trial)
49+
public void init() {
50+
super.init();
51+
filter = type.construct(keys, 64);
52+
keysToFind = new long[1 << logDistinctLookups];
53+
int memberCount = (int)(trueMatchProbability * keysToFind.length);
54+
if (memberCount > keys.length) {
55+
throw new AssertionError("Benchmark setup error: expect at least "
56+
+ memberCount + " keys but have " + keys.length);
57+
}
58+
System.arraycopy(keys, 0, keysToFind, 0, memberCount);
59+
}
60+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.fastfilter;
2+
3+
import java.util.SplittableRandom;
4+
5+
public enum KeyGenerationStrategy {
6+
RANDOM64 {
7+
SplittableRandom random = new SplittableRandom(Environment.SEED);
8+
@Override
9+
void fill(long[] keys) {
10+
for (int i = 0; i < keys.length; ++i) {
11+
keys[i] = random.nextLong();
12+
}
13+
}
14+
},
15+
RANDOM32 {
16+
SplittableRandom random = new SplittableRandom(Environment.SEED);
17+
@Override
18+
void fill(long[] keys) {
19+
for (int i = 0; i < keys.length; ++i) {
20+
keys[i] = random.nextInt();
21+
}
22+
}
23+
};
24+
25+
abstract void fill(long[] keys);
26+
}

0 commit comments

Comments
 (0)