Bitcoin Core 31.99.0
P2P Digital Currency
streams_findbyte.cpp
Go to the documentation of this file.
1// Copyright (c) 2023-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 <streams.h>
8#include <util/fs.h>
9
10#include <cstddef>
11#include <cstdint>
12#include <cstdio>
13
14static void FindByte(benchmark::Bench& bench)
15{
16 const auto testing_setup{MakeNoLogFileContext<const BasicTestingSetup>(ChainType::REGTEST)};
17 AutoFile file{fsbridge::fopen(testing_setup->m_path_root / "streams_tmp", "w+b")};
18 const size_t file_size = 200;
19 uint8_t data[file_size] = {0};
20 data[file_size - 1] = 1;
21 file << data;
22 file.seek(0, SEEK_SET);
23 BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size};
24
25 bench.setup([&] { bf.SetPos(0); })
26 .run([&] { bf.FindByte(std::byte(1)); });
27
28 assert(file.fclose() == 0);
29}
30
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:381
Wrapper around an AutoFile& that implements a ring buffer to deserialize from.
Definition: streams.h:491
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:633
detail::SetupRunner< SetupOp > setup(SetupOp setupOp)
Configure an untimed setup step per epoch (forces single-iteration epochs).
Definition: nanobench.h:1286
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:23
BENCHMARK(FindByte)
static void FindByte(benchmark::Bench &bench)
assert(!tx.IsCoinBase())