Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
gcs_filter.cpp
Go to the documentation of this file.
1// Copyright (c) 2018-2022 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
12 // Testing the benchmarks with different number of elements show that a filter
13 // with at least 100,000 elements results in benchmarks that have the same
14 // ns/op. This makes it easy to reason about how long (in nanoseconds) a single
15 // filter element takes to process.
16 for (int i = 0; i < 100000; ++i) {
17 GCSFilter::Element element(32);
18 element[0] = static_cast<unsigned char>(i);
19 element[1] = static_cast<unsigned char>(i >> 8);
20 elements.insert(std::move(element));
21 }
22
23 return elements;
24}
25
27{
28 auto elements = GenerateGCSTestElements();
29
30 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
31 BlockFilter block_filter(BlockFilterType::BASIC, {}, filter.GetEncoded(), /*skip_decode_check=*/false);
32
33 bench.run([&] {
34 block_filter.GetHash();
35 });
36}
37
39{
40 auto elements = GenerateGCSTestElements();
41
42 uint64_t siphash_k0 = 0;
43 bench.run([&]{
44 GCSFilter filter({siphash_k0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
45
46 siphash_k0++;
47 });
48}
49
51{
52 auto elements = GenerateGCSTestElements();
53
54 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
55 auto encoded = filter.GetEncoded();
56
57 bench.run([&] {
58 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, encoded, /*skip_decode_check=*/false);
59 });
60}
61
63{
64 auto elements = GenerateGCSTestElements();
65
66 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
67 auto encoded = filter.GetEncoded();
68
69 bench.run([&] {
70 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, encoded, /*skip_decode_check=*/true);
71 });
72}
73
75{
76 auto elements = GenerateGCSTestElements();
77
78 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);
79
80 bench.run([&] {
81 filter.Match(GCSFilter::Element());
82 });
83}
#define BENCHMARK(n, priority_level)
Definition bench.h:79
constexpr uint8_t BASIC_FILTER_P
Definition blockfilter.h:89
constexpr uint32_t BASIC_FILTER_M
Definition blockfilter.h:90
Complete block filter struct as defined in BIP 157.
This implements a Golomb-coded set as defined in BIP 158.
Definition blockfilter.h:29
std::unordered_set< Element, ByteVectorHash > ElementSet
Definition blockfilter.h:32
std::vector< unsigned char > Element
Definition blockfilter.h:31
const std::vector< unsigned char > & GetEncoded() const LIFETIMEBOUND
Definition blockfilter.h:73
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition nanobench.h:1234
static void GCSFilterConstruct(benchmark::Bench &bench)
static GCSFilter::ElementSet GenerateGCSTestElements()
Definition gcs_filter.cpp:8
static void GCSFilterDecode(benchmark::Bench &bench)
static void GCSBlockFilterGetHash(benchmark::Bench &bench)
static void GCSFilterDecodeSkipCheck(benchmark::Bench &bench)
static void GCSFilterMatch(benchmark::Bench &bench)
@ HIGH
Definition bench.h:47