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