Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
gcs_filter.cpp
Go to the documentation of this file.
1// Copyright (c) 2018-present 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#include <uint256.h>
8
9#include <cstdint>
10#include <utility>
11#include <vector>
12
14{
16
17 // Testing the benchmarks with different number of elements show that a filter
18 // with at least 100,000 elements results in benchmarks that have the same
19 // ns/op. This makes it easy to reason about how long (in nanoseconds) a single
20 // filter element takes to process.
21 for (int i = 0; i < 100000; ++i) {
23 element[0] = static_cast<unsigned char>(i);
24 element[1] = static_cast<unsigned char>(i >> 8);
25 elements.insert(std::move(element));
26 }
27
28 return elements;
29}
30
32{
34
36 BlockFilter block_filter(BlockFilterType::BASIC, {}, filter.GetEncoded(), /*skip_decode_check=*/false);
37
38 bench.run([&] {
39 block_filter.GetHash();
40 });
41}
42
44{
46
48 bench.run([&]{
50
51 siphash_k0++;
52 });
53}
54
56{
58
60 auto encoded = filter.GetEncoded();
61
62 bench.run([&] {
63 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, encoded, /*skip_decode_check=*/false);
64 });
65}
66
68{
70
72 auto encoded = filter.GetEncoded();
73
74 bench.run([&] {
75 GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, encoded, /*skip_decode_check=*/true);
76 });
77}
78
80{
82
84
85 bench.run([&] {
86 filter.Match(GCSFilter::Element());
87 });
88}
#define BENCHMARK(n)
Definition bench.h:68
constexpr uint8_t BASIC_FILTER_P
Definition blockfilter.h:90
constexpr uint32_t BASIC_FILTER_M
Definition blockfilter.h:91
Complete block filter struct as defined in BIP 157.
This implements a Golomb-coded set as defined in BIP 158.
Definition blockfilter.h:30
std::vector< unsigned char > Element
Definition blockfilter.h:32
std::unordered_set< Element, ByteVectorHash > ElementSet
Definition blockfilter.h:33
const std::vector< unsigned char > & GetEncoded() const LIFETIMEBOUND
Definition blockfilter.h:74
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:627
static void GCSFilterConstruct(benchmark::Bench &bench)
static GCSFilter::ElementSet GenerateGCSTestElements()
static void GCSFilterDecode(benchmark::Bench &bench)
static void GCSBlockFilterGetHash(benchmark::Bench &bench)
static void GCSFilterDecodeSkipCheck(benchmark::Bench &bench)
static void GCSFilterMatch(benchmark::Bench &bench)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73