PIVX Core  5.6.99
P2P Digital Currency
rollingbloom.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016 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 <iostream>
6 
7 #include "bench.h"
8 #include "bloom.h"
9 #include "utiltime.h"
10 
11 static void RollingBloom(benchmark::State& state)
12 {
13  CRollingBloomFilter filter(120000, 0.000001);
14  std::vector<unsigned char> data(32);
15  uint32_t count = 0;
16  uint32_t nEntriesPerGeneration = (120000 + 1) / 2;
17  uint32_t countnow = 0;
18  uint64_t match = 0;
19  while (state.KeepRunning()) {
20  count++;
21  data[0] = count;
22  data[1] = count >> 8;
23  data[2] = count >> 16;
24  data[3] = count >> 24;
25  if (countnow == nEntriesPerGeneration) {
26  int64_t b = GetTimeMicros();
27  filter.insert(data);
28  int64_t e = GetTimeMicros();
29  std::cout << "RollingBloom-refresh,1," << (e-b)*0.000001 << "," << (e-b)*0.000001 << "," << (e-b)*0.000001 << "\n";
30  countnow = 0;
31  } else {
32  filter.insert(data);
33  }
34  countnow++;
35  data[0] = count >> 24;
36  data[1] = count >> 16;
37  data[2] = count >> 8;
38  data[3] = count;
39  match += filter.contains(data);
40  }
41 }
42 
43 BENCHMARK(RollingBloom, 1500 * 1000);
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:111
bool KeepRunning()
Definition: bench.h:69
BENCHMARK(RollingBloom, 1500 *1000)
int64_t GetTimeMicros()
Returns the system time (not mockable)
Definition: utiltime.cpp:74