rollingbloom.cpp raw

   1  // Copyright (c) 2016-present 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 <common/bloom.h>
   7  #include <crypto/common.h>
   8  
   9  #include <cstdint>
  10  #include <span>
  11  #include <vector>
  12  
  13  static void RollingBloom(benchmark::Bench& bench)
  14  {
  15      CRollingBloomFilter filter(120000, 0.000001);
  16      std::vector<unsigned char> data(32);
  17      uint32_t count = 0;
  18      bench.run([&] {
  19          count++;
  20          WriteLE32(data.data(), count);
  21          filter.insert(data);
  22  
  23          WriteBE32(data.data(), count);
  24          filter.contains(data);
  25      });
  26  }
  27  
  28  static void RollingBloomReset(benchmark::Bench& bench)
  29  {
  30      CRollingBloomFilter filter(120000, 0.000001);
  31      bench.run([&] {
  32          filter.reset();
  33      });
  34  }
  35  
  36  BENCHMARK(RollingBloom);
  37  BENCHMARK(RollingBloomReset);
  38