Skip to content

Commit 604df63

Browse files
glozowLarryRuane
authored andcommitted
[bench] add streams findbyte
1 parent 6c7ebcc commit 604df63

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ bench_bench_bitcoin_SOURCES = \
4747
bench/rollingbloom.cpp \
4848
bench/rpc_blockchain.cpp \
4949
bench/rpc_mempool.cpp \
50+
bench/streams_findbyte.cpp \
5051
bench/strencodings.cpp \
5152
bench/util_time.cpp \
5253
bench/verify_script.cpp

src/bench/streams_findbyte.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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(1);
24+
});
25+
26+
// Cleanup
27+
bf.fclose();
28+
fs::remove("streams_tmp");
29+
}
30+
31+
BENCHMARK(FindByte, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)