Bitcoin Core 22.99.0
P2P Digital Currency
gcs_filter.cpp
Go to the documentation of this file.
1// Copyright (c) 2018-2020 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
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 bench.batch(elements.size()).unit("elem").run([&] {
20 GCSFilter filter({siphash_k0, 0, 20, 1 << 20}, elements);
21
22 siphash_k0++;
23 });
24}
25
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 bench.unit("elem").run([&] {
38 filter.Match(GCSFilter::Element());
39 });
40}
41
This implements a Golomb-coded set as defined in BIP 158.
Definition: blockfilter.h:25
std::vector< unsigned char > Element
Definition: blockfilter.h:27
std::unordered_set< Element, ByteVectorHash > ElementSet
Definition: blockfilter.h:28
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
ANKERL_NANOBENCH(NODISCARD) std Bench & batch(T b) noexcept
Sets the batch size.
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
Bench & unit(char const *unit)
Sets the operation unit.
static void ConstructGCSFilter(benchmark::Bench &bench)
Definition: gcs_filter.cpp:8
static void MatchGCSFilter(benchmark::Bench &bench)
Definition: gcs_filter.cpp:26
BENCHMARK(ConstructGCSFilter)