Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2018-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bench/bench.h>6#include <blockfilter.h>7#include <uint256.h>9#include <cstdint>10#include <utility>11#include <vector>13static GCSFilter::ElementSet GenerateGCSTestElements()14{15GCSFilter::ElementSet elements;17// Testing the benchmarks with different number of elements show that a filter18// with at least 100,000 elements results in benchmarks that have the same19// ns/op. This makes it easy to reason about how long (in nanoseconds) a single20// filter element takes to process.21for (int i = 0; i < 100000; ++i) {22GCSFilter::Element element(32);23element[0] = static_cast<unsigned char>(i);24element[1] = static_cast<unsigned char>(i >> 8);25elements.insert(std::move(element));26}28return elements;29}31static void GCSBlockFilterGetHash(benchmark::Bench& bench)32{33auto elements = GenerateGCSTestElements();35GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);36BlockFilter block_filter(BlockFilterType::BASIC, {}, filter.GetEncoded(), /*skip_decode_check=*/false);38bench.run([&] {39block_filter.GetHash();40});41}43static void GCSFilterConstruct(benchmark::Bench& bench)44{45auto elements = GenerateGCSTestElements();47uint64_t siphash_k0 = 0;48bench.run([&]{49GCSFilter filter({siphash_k0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);51siphash_k0++;52});53}55static void GCSFilterDecode(benchmark::Bench& bench)56{57auto elements = GenerateGCSTestElements();59GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);60auto encoded = filter.GetEncoded();62bench.run([&] {63GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, encoded, /*skip_decode_check=*/false);64});65}67static void GCSFilterDecodeSkipCheck(benchmark::Bench& bench)68{69auto elements = GenerateGCSTestElements();71GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);72auto encoded = filter.GetEncoded();74bench.run([&] {75GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, encoded, /*skip_decode_check=*/true);76});77}79static void GCSFilterMatch(benchmark::Bench& bench)80{81auto elements = GenerateGCSTestElements();83GCSFilter filter({0, 0, BASIC_FILTER_P, BASIC_FILTER_M}, elements);85bench.run([&] {86filter.Match(GCSFilter::Element());87});88}89BENCHMARK(GCSBlockFilterGetHash);90BENCHMARK(GCSFilterConstruct);91BENCHMARK(GCSFilterDecode);92BENCHMARK(GCSFilterDecodeSkipCheck);93BENCHMARK(GCSFilterMatch);
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.