Skip to content

Commit 254c85b

Browse files
committed
bench: Benchmark GCS filter creation and matching.
1 parent f33b717 commit 254c85b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ bench_bench_bitcoin_SOURCES = \
2222
bench/rollingbloom.cpp \
2323
bench/crypto_hash.cpp \
2424
bench/ccoins_caching.cpp \
25+
bench/gcs_filter.cpp \
2526
bench/merkle_root.cpp \
2627
bench/mempool_eviction.cpp \
2728
bench/verify_script.cpp \

src/bench/gcs_filter.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2018 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <bench/bench.h>
6+
#include <blockfilter.h>
7+
8+
static void ConstructGCSFilter(benchmark::State& state)
9+
{
10+
GCSFilter::ElementSet elements;
11+
for (int i = 0; i < 10000; ++i) {
12+
GCSFilter::Element element(32);
13+
element[0] = static_cast<unsigned char>(i);
14+
element[1] = static_cast<unsigned char>(i >> 8);
15+
elements.insert(std::move(element));
16+
}
17+
18+
uint64_t siphash_k0 = 0;
19+
while (state.KeepRunning()) {
20+
GCSFilter filter(siphash_k0, 0, 20, 1 << 20, elements);
21+
22+
siphash_k0++;
23+
}
24+
}
25+
26+
static void MatchGCSFilter(benchmark::State& state)
27+
{
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);
36+
37+
while (state.KeepRunning()) {
38+
filter.Match(GCSFilter::Element());
39+
}
40+
}
41+
42+
BENCHMARK(ConstructGCSFilter, 1000);
43+
BENCHMARK(MatchGCSFilter, 50 * 1000);

0 commit comments

Comments
 (0)