// Copyright (c) 2016 The Bitcoin Core developers // Copyright (c) 2020-2023 The Zcash developers // Distributed under the MIT software license, see the accompanying // file COPYING or https://www.opensource.org/licenses/mit-license.php . #include #include "bench.h" #include "bloom.h" static void RollingBloom(benchmark::State& state) { CRollingBloomFilter filter(120000, 0.000001); std::vector data(32); uint32_t count = 0; uint32_t nEntriesPerGeneration = (120000 + 1) / 2; uint32_t countnow = 0; uint64_t match = 0; while (state.KeepRunning()) { count++; data[0] = count; data[1] = count >> 8; data[2] = count >> 16; data[3] = count >> 24; if (countnow == nEntriesPerGeneration) { auto b = benchmark::clock::now(); filter.insert(data); auto total = std::chrono::duration_cast(benchmark::clock::now() - b).count(); std::cout << "RollingBloom-refresh,1," << total << "," << total << "," << total << "\n"; countnow = 0; } else { filter.insert(data); } countnow++; data[0] = count >> 24; data[1] = count >> 16; data[2] = count >> 8; data[3] = count; match += filter.contains(data); } } static void RollingBloomReset(benchmark::State& state) { CRollingBloomFilter filter(120000, 0.000001); while (state.KeepRunning()) { filter.reset(); } } BENCHMARK(RollingBloom); BENCHMARK(RollingBloomReset); // To-backport: 20000