Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
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/check.h>
9#include <util/fs.h>
10
11#include <cstddef>
12#include <cstdint>
13#include <cstdio>
14#include <memory>
15
16static void FindByte(benchmark::Bench& bench)
17{
19 AutoFile file{fsbridge::fopen(testing_setup->m_path_root / "streams_tmp", "w+b")};
20 const size_t file_size = 200;
21 uint8_t data[file_size] = {0};
22 data[file_size - 1] = 1;
23 file << data;
24 file.seek(0, SEEK_SET);
25 BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size};
26
27 bench.setup([&] { bf.SetPos(0); })
28 .run([&] { bf.FindByte(std::byte(1)); });
29
30 assert(file.fclose() == 0);
31}
32
#define BENCHMARK(n)
Definition bench.h:69
Non-refcounted RAII wrapper for FILE*.
Definition streams.h:395
void seek(int64_t offset, int origin)
Wrapper around fseek().
Definition streams.cpp:33
int fclose()
Definition streams.h:429
Wrapper around an AutoFile& that implements a ring buffer to deserialize from.
Definition streams.h:505
void FindByte(std::byte byte)
search for a given byte in the stream, and remain positioned on it
Definition streams.h:622
bool SetPos(uint64_t nPos)
rewind to a given reading position
Definition streams.h:590
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:649
detail::SetupRunner< SetupOp > setup(SetupOp setupOp)
Configure an untimed setup step per epoch (forces single-iteration epochs).
Definition nanobench.h:1302
FILE * fopen(const fs::path &p, const char *mode)
Definition fs.cpp:23
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
static void FindByte(benchmark::Bench &bench)
assert(!tx.IsCoinBase())