Bitcoin Core  24.99.0
P2P Digital Currency
rollingbloom.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016-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 
6 #include <bench/bench.h>
7 #include <common/bloom.h>
8 #include <crypto/common.h>
9 
10 #include <vector>
11 
12 static void RollingBloom(benchmark::Bench& bench)
13 {
14  CRollingBloomFilter filter(120000, 0.000001);
15  std::vector<unsigned char> data(32);
16  uint32_t count = 0;
17  bench.run([&] {
18  count++;
19  WriteLE32(data.data(), count);
20  filter.insert(data);
21 
22  WriteBE32(data.data(), count);
23  filter.contains(data);
24  });
25 }
26 
28 {
29  CRollingBloomFilter filter(120000, 0.000001);
30  bench.run([&] {
31  filter.reset();
32  });
33 }
34 
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:109
bool contains(Span< const unsigned char > vKey) const
Definition: bloom.cpp:226
void insert(Span< const unsigned char > vKey)
Definition: bloom.cpp:195
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
static void WriteBE32(unsigned char *ptr, uint32_t x)
Definition: common.h:77
static void WriteLE32(unsigned char *ptr, uint32_t x)
Definition: common.h:44
@ HIGH
Definition: bench.h:47
static void RollingBloom(benchmark::Bench &bench)
BENCHMARK(RollingBloom, benchmark::PriorityLevel::HIGH)
static void RollingBloomReset(benchmark::Bench &bench)
static int count
Definition: tests.c:34