Bitcoin Core  25.99.0
P2P Digital Currency
streams_findbyte.cpp
Go to the documentation of this file.
1 // Copyright (c) 2023 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 
7 #include <util/fs.h>
8 #include <streams.h>
9 
10 static void FindByte(benchmark::Bench& bench)
11 {
12  // Setup
13  FILE* file = fsbridge::fopen("streams_tmp", "w+b");
14  const size_t file_size = 200;
15  uint8_t data[file_size] = {0};
16  data[file_size-1] = 1;
17  fwrite(&data, sizeof(uint8_t), file_size, file);
18  rewind(file);
19  CBufferedFile bf(file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0, 0);
20 
21  bench.run([&] {
22  bf.SetPos(0);
23  bf.FindByte(std::byte(1));
24  });
25 
26  // Cleanup
27  bf.fclose();
28  fs::remove("streams_tmp");
29 }
30 
Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to deserialize from.
Definition: streams.h:617
void FindByte(std::byte byte)
search for a given byte in the stream, and remain positioned on it
Definition: streams.h:759
bool SetPos(uint64_t nPos)
rewind to a given reading position
Definition: streams.h:726
void fclose()
Definition: streams.h:689
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:623
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1230
@ HIGH
Definition: bench.h:47
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:25
BENCHMARK(FindByte, benchmark::PriorityLevel::HIGH)
static void FindByte(benchmark::Bench &bench)