Bitcoin ABC  0.22.12
P2P Digital Currency
gcs_filter.cpp
Go to the documentation of this file.
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) {
10  for (int i = 0; i < 10000; ++i) {
11  GCSFilter::Element element(32);
12  element[0] = static_cast<uint8_t>(i);
13  element[1] = static_cast<uint8_t>(i >> 8);
14  elements.insert(std::move(element));
15  }
16 
17  uint64_t siphash_k0 = 0;
18  while (state.KeepRunning()) {
19  GCSFilter filter({siphash_k0, 0, 20, 1 << 20}, elements);
20 
21  siphash_k0++;
22  }
23 }
24 
25 static void MatchGCSFilter(benchmark::State &state) {
27  for (int i = 0; i < 10000; ++i) {
28  GCSFilter::Element element(32);
29  element[0] = static_cast<uint8_t>(i);
30  element[1] = static_cast<uint8_t>(i >> 8);
31  elements.insert(std::move(element));
32  }
33  GCSFilter filter({0, 0, 20, 1 << 20}, elements);
34 
35  while (state.KeepRunning()) {
36  filter.Match(GCSFilter::Element());
37  }
38 }
39 
41 BENCHMARK(MatchGCSFilter, 50 * 1000);
bool KeepRunning()
Definition: bench.h:75
bool Match(const Element &element) const
Checks if the element may be in the set.
static void ConstructGCSFilter(benchmark::State &state)
Definition: gcs_filter.cpp:8
static unsigned char elements[DATACOUNT][DATALEN]
Definition: tests_impl.h:36
This implements a Golomb-coded set as defined in BIP 158.
Definition: blockfilter.h:25
std::unordered_set< Element, ByteVectorHash > ElementSet
Definition: blockfilter.h:28
std::vector< uint8_t > Element
Definition: blockfilter.h:27
static void MatchGCSFilter(benchmark::State &state)
Definition: gcs_filter.cpp:25
BENCHMARK(ConstructGCSFilter, 1000)