2020-08-10 11:28:28 -07:00
|
|
|
// 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 <streams.h>
|
2023-07-04 18:59:49 +02:00
|
|
|
#include <util/fs.h>
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstdio>
|
2020-08-10 11:28:28 -07:00
|
|
|
|
|
|
|
static void FindByte(benchmark::Bench& bench)
|
|
|
|
{
|
|
|
|
// Setup
|
2023-11-15 13:10:13 +10:00
|
|
|
AutoFile file{fsbridge::fopen("streams_tmp", "w+b")};
|
2020-08-10 11:28:28 -07:00
|
|
|
const size_t file_size = 200;
|
|
|
|
uint8_t data[file_size] = {0};
|
|
|
|
data[file_size-1] = 1;
|
2023-07-04 18:59:49 +02:00
|
|
|
file << data;
|
|
|
|
std::rewind(file.Get());
|
2023-07-04 17:09:13 +02:00
|
|
|
BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size};
|
2020-08-10 11:28:28 -07:00
|
|
|
|
|
|
|
bench.run([&] {
|
|
|
|
bf.SetPos(0);
|
2020-08-10 15:23:03 -06:00
|
|
|
bf.FindByte(std::byte(1));
|
2020-08-10 11:28:28 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Cleanup
|
2023-07-04 18:59:49 +02:00
|
|
|
file.fclose();
|
2020-08-10 11:28:28 -07:00
|
|
|
fs::remove("streams_tmp");
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(FindByte, benchmark::PriorityLevel::HIGH);
|