Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
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
>
7
#include <
test/util/setup_common.h
>
8
#include <
util/fs.h
>
9
10
#include <cstddef>
11
#include <cstdint>
12
#include <cstdio>
13
14
static
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.
run
([&] {
26
bf.
SetPos
(0);
27
bf.
FindByte
(std::byte(1));
28
});
29
30
assert
(file.
fclose
() == 0);
31
}
32
33
BENCHMARK
(
FindByte
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
ChainType::REGTEST
@ REGTEST
Definition
chaintype.h:15
AutoFile
Non-refcounted RAII wrapper for FILE*.
Definition
streams.h:373
AutoFile::seek
void seek(int64_t offset, int origin)
Wrapper around fseek().
Definition
streams.cpp:33
AutoFile::fclose
int fclose()
Definition
streams.h:407
BufferedFile
Wrapper around an AutoFile& that implements a ring buffer to deserialize from.
Definition
streams.h:483
BufferedFile::FindByte
void FindByte(std::byte byte)
search for a given byte in the stream, and remain positioned on it
Definition
streams.h:600
BufferedFile::SetPos
bool SetPos(uint64_t nPos)
rewind to a given reading position
Definition
streams.h:568
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
fs.h
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition
fs.cpp:25
setup_common.h
MakeNoLogFileContext
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.
Definition
setup_common.h:250
streams.h
FindByte
static void FindByte(benchmark::Bench &bench)
Definition
streams_findbyte.cpp:14
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0