Raven Core  3.0.0
P2P Digital Currency
rollingbloom.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <iostream>
7 
8 #include "bench.h"
9 #include "bloom.h"
10 #include "utiltime.h"
11 
12 static void RollingBloom(benchmark::State& state)
13 {
14  CRollingBloomFilter filter(120000, 0.000001);
15  std::vector<unsigned char> data(32);
16  uint32_t count = 0;
17  uint32_t nEntriesPerGeneration = (120000 + 1) / 2;
18  uint32_t countnow = 0;
19  uint64_t match = 0;
20  while (state.KeepRunning()) {
21  count++;
22  data[0] = count;
23  data[1] = count >> 8;
24  data[2] = count >> 16;
25  data[3] = count >> 24;
26  if (countnow == nEntriesPerGeneration) {
27  int64_t b = GetTimeMicros();
28  filter.insert(data);
29  int64_t e = GetTimeMicros();
30  std::cout << "RollingBloom-refresh,1," << (e-b)*0.000001 << "," << (e-b)*0.000001 << "," << (e-b)*0.000001 << "\n";
31  countnow = 0;
32  } else {
33  filter.insert(data);
34  }
35  countnow++;
36  data[0] = count >> 24;
37  data[1] = count >> 16;
38  data[2] = count >> 8;
39  data[3] = count;
40  match += filter.contains(data);
41  }
42 }
43 
44 BENCHMARK(RollingBloom);
bool KeepRunning()
Definition: bench.cpp:44
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. ...
Definition: bloom.h:120
int64_t GetTimeMicros()
Definition: utiltime.cpp:48
BENCHMARK(RollingBloom)