Skip to content

Commit 299023c

Browse files
pstratemkcalvinalvin
authored andcommitted
Add GCSFilterDecode and GCSBlockFilterGetHash benchmarks.
All of the benchmarks are standardized on the BASIC filter parameters so we can compare between all the benchmarks. All the GCS benchmarks are renamed to have "GCS" as the prefix.
1 parent b0a53d5 commit 299023c

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

src/bench/gcs_filter.cpp

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <bench/bench.h>
66
#include <blockfilter.h>
77

8-
static void ConstructGCSFilter(benchmark::Bench& bench)
8+
static const GCSFilter::ElementSet GenerateGCSTestElements()
99
{
1010
GCSFilter::ElementSet elements;
1111
for (int i = 0; i < 10000; ++i) {
@@ -15,29 +15,56 @@ static void ConstructGCSFilter(benchmark::Bench& bench)
1515
elements.insert(std::move(element));
1616
}
1717

18+
return elements;
19+
}
20+
21+
static void GCSBlockFilterGetHash(benchmark::Bench& bench)
22+
{
23+
auto elements = GenerateGCSTestElements();
24+
25+
GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
26+
BlockFilter block_filter(BlockFilterType::BASIC, {}, filter.GetEncoded(), /*skip_decode_check=*/false);
27+
28+
bench.run([&] {
29+
block_filter.GetHash();
30+
});
31+
}
32+
33+
static void GCSFilterConstruct(benchmark::Bench& bench)
34+
{
35+
auto elements = GenerateGCSTestElements();
36+
1837
uint64_t siphash_k0 = 0;
1938
bench.batch(elements.size()).unit("elem").run([&] {
20-
GCSFilter filter({siphash_k0, 0, 20, 1 << 20}, elements);
39+
GCSFilter filter({siphash_k0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
2140

2241
siphash_k0++;
2342
});
2443
}
2544

26-
static void MatchGCSFilter(benchmark::Bench& bench)
45+
static void GCSFilterDecode(benchmark::Bench& bench)
2746
{
28-
GCSFilter::ElementSet elements;
29-
for (int i = 0; i < 10000; ++i) {
30-
GCSFilter::Element element(32);
31-
element[0] = static_cast<unsigned char>(i);
32-
element[1] = static_cast<unsigned char>(i >> 8);
33-
elements.insert(std::move(element));
34-
}
35-
GCSFilter filter({0, 0, 20, 1 << 20}, elements);
47+
auto elements = GenerateGCSTestElements();
3648

37-
bench.unit("elem").run([&] {
38-
filter.Match(GCSFilter::Element());
49+
GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
50+
auto encoded = filter.GetEncoded();
51+
52+
bench.run([&] {
53+
GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, encoded, /*skip_decode_check=*/false);
3954
});
4055
}
4156

42-
BENCHMARK(ConstructGCSFilter);
43-
BENCHMARK(MatchGCSFilter);
57+
static void GCSFilterMatch(benchmark::Bench& bench)
58+
{
59+
auto elements = GenerateGCSTestElements();
60+
61+
GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
62+
63+
bench.run([&] {
64+
filter.Match(GCSFilter::Element());
65+
});
66+
}
67+
BENCHMARK(GCSBlockFilterGetHash);
68+
BENCHMARK(GCSFilterConstruct);
69+
BENCHMARK(GCSFilterDecode);
70+
BENCHMARK(GCSFilterMatch);

0 commit comments

Comments
 (0)