Skip to content

Commit b576994

Browse files
glozowLarryRuane
authored andcommitted
[bench] streams findbyte
1 parent e349eee commit b576994

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Makefile.bench.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ bench_bench_bitcoin_SOURCES = \
4343
bench/bech32.cpp \
4444
bench/lockedpool.cpp \
4545
bench/poly1305.cpp \
46-
bench/prevector.cpp
46+
bench/prevector.cpp \
47+
bench/streams_findbyte.cpp
4748

4849
nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
4950

src/bench/streams_findbyte.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2020 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+
9+
static void FindByte(benchmark::Bench& bench)
10+
{
11+
// Setup
12+
FILE* file = fsbridge::fopen("streams_tmp", "w+b");
13+
const size_t fileSize = 200;
14+
uint8_t b = 0;
15+
for (size_t i = 0; i < fileSize; ++i) {
16+
fwrite(&b, 1, 1, file);
17+
}
18+
b = 1;
19+
fwrite(&b, 1, 1, file);
20+
rewind(file);
21+
CBufferedFile bf(file, fileSize * 2, fileSize, 0, 0);
22+
23+
bench.minEpochIterations(1e7).run([&] {
24+
bf.SetPos(0);
25+
bf.FindByte(1);
26+
});
27+
28+
// Cleanup
29+
bf.fclose();
30+
fs::remove("streams_tmp");
31+
}
32+
33+
BENCHMARK(FindByte);

0 commit comments

Comments
 (0)