Skip to content

Commit

Permalink
bench: Benchmark GCS filter creation and matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimpo committed Aug 25, 2018
1 parent f33b717 commit 254c85b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.bench.include
Expand Up @@ -22,6 +22,7 @@ bench_bench_bitcoin_SOURCES = \
bench/rollingbloom.cpp \
bench/crypto_hash.cpp \
bench/ccoins_caching.cpp \
bench/gcs_filter.cpp \
bench/merkle_root.cpp \
bench/mempool_eviction.cpp \
bench/verify_script.cpp \
Expand Down
43 changes: 43 additions & 0 deletions src/bench/gcs_filter.cpp
@@ -0,0 +1,43 @@
// Copyright (c) 2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <bench/bench.h>
#include <blockfilter.h>

static void ConstructGCSFilter(benchmark::State& state)
{
GCSFilter::ElementSet elements;
for (int i = 0; i < 10000; ++i) {
GCSFilter::Element element(32);
element[0] = static_cast<unsigned char>(i);
element[1] = static_cast<unsigned char>(i >> 8);
elements.insert(std::move(element));
}

uint64_t siphash_k0 = 0;
while (state.KeepRunning()) {
GCSFilter filter(siphash_k0, 0, 20, 1 << 20, elements);

siphash_k0++;
}
}

static void MatchGCSFilter(benchmark::State& state)
{
GCSFilter::ElementSet elements;
for (int i = 0; i < 10000; ++i) {
GCSFilter::Element element(32);
element[0] = static_cast<unsigned char>(i);
element[1] = static_cast<unsigned char>(i >> 8);
elements.insert(std::move(element));
}
GCSFilter filter(0, 0, 20, 1 << 20, elements);

while (state.KeepRunning()) {
filter.Match(GCSFilter::Element());
}
}

BENCHMARK(ConstructGCSFilter, 1000);
BENCHMARK(MatchGCSFilter, 50 * 1000);

0 comments on commit 254c85b

Please sign in to comment.