Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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 <streams.h>
8#include <util/fs.h>
9
11 // Setup
12 FILE *file = fsbridge::fopen("streams_tmp", "w+b");
13 const size_t file_size = 200;
14 uint8_t data[file_size] = {0};
15 data[file_size - 1] = 1;
16 fwrite(&data, sizeof(uint8_t), file_size, file);
17 rewind(file);
18 CBufferedFile bf(file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size,
19 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
#define BENCHMARK(n)
Definition bench.h:65
Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to deserialize from.
Definition streams.h:671
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:616
FILE * fopen(const fs::path &p, const char *mode)
Definition fs.cpp:30
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
static void FindByte(benchmark::Bench &bench)