rollingbloom.cpp raw

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