Files
bitcoin/src/bench/streams_findbyte.cpp
Lőrinc e6430b2773 bench: make setup() use single-iteration epochs
`setup()` in nanobench runs once per epoch, not once per timed call.
If an epoch executes the benchmark body multiple times, `setup()` can silently leave later iterations with different preconditions.

Make `setup()` force `epochIterations(1)` itself: keep rejecting incompatible larger explicit epoch sizes, but allow existing single-iteration callers such as `-sanity-check`.

With `setup()` handling this centrally, remove the redundant `epochIterations(1)` calls from the benchmarks that use it.

Co-authored-by: David Gumberg <davidzgumberg@gmail.com>
2026-04-23 20:54:40 +02:00

32 lines
962 B
C++

// Copyright (c) 2023-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <bench/bench.h>
#include <streams.h>
#include <test/util/setup_common.h>
#include <util/fs.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
static void FindByte(benchmark::Bench& bench)
{
const auto testing_setup{MakeNoLogFileContext<const BasicTestingSetup>(ChainType::REGTEST)};
AutoFile file{fsbridge::fopen(testing_setup->m_path_root / "streams_tmp", "w+b")};
const size_t file_size = 200;
uint8_t data[file_size] = {0};
data[file_size - 1] = 1;
file << data;
file.seek(0, SEEK_SET);
BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size};
bench.setup([&] { bf.SetPos(0); })
.run([&] { bf.FindByte(std::byte(1)); });
assert(file.fclose() == 0);
}
BENCHMARK(FindByte);