From 604df63f6c70b9692b067777ddb38d946ac0b2fc Mon Sep 17 00:00:00 2001 From: gzhao408 Date: Mon, 10 Aug 2020 11:28:28 -0700 Subject: [PATCH] [bench] add streams findbyte --- src/Makefile.bench.include | 1 + src/bench/streams_findbyte.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/bench/streams_findbyte.cpp diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index c230728a1c..c8e510b482 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -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 diff --git a/src/bench/streams_findbyte.cpp b/src/bench/streams_findbyte.cpp new file mode 100644 index 0000000000..70722ee4d8 --- /dev/null +++ b/src/bench/streams_findbyte.cpp @@ -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 + +#include +#include + +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);