mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 19:37:27 -03:00
[bench] add streams findbyte
This commit is contained in:
parent
6c7ebcc14b
commit
604df63f6c
2 changed files with 32 additions and 0 deletions
|
@ -47,6 +47,7 @@ bench_bench_bitcoin_SOURCES = \
|
|||
bench/rollingbloom.cpp \
|
||||
bench/rpc_blockchain.cpp \
|
||||
bench/rpc_mempool.cpp \
|
||||
bench/streams_findbyte.cpp \
|
||||
bench/strencodings.cpp \
|
||||
bench/util_time.cpp \
|
||||
bench/verify_script.cpp
|
||||
|
|
31
src/bench/streams_findbyte.cpp
Normal file
31
src/bench/streams_findbyte.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2023 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <bench/bench.h>
|
||||
|
||||
#include <util/fs.h>
|
||||
#include <streams.h>
|
||||
|
||||
static void FindByte(benchmark::Bench& bench)
|
||||
{
|
||||
// Setup
|
||||
FILE* file = fsbridge::fopen("streams_tmp", "w+b");
|
||||
const size_t file_size = 200;
|
||||
uint8_t data[file_size] = {0};
|
||||
data[file_size-1] = 1;
|
||||
fwrite(&data, sizeof(uint8_t), file_size, file);
|
||||
rewind(file);
|
||||
CBufferedFile bf(file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0, 0);
|
||||
|
||||
bench.run([&] {
|
||||
bf.SetPos(0);
|
||||
bf.FindByte(1);
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
bf.fclose();
|
||||
fs::remove("streams_tmp");
|
||||
}
|
||||
|
||||
BENCHMARK(FindByte, benchmark::PriorityLevel::HIGH);
|
Loading…
Reference in a new issue