Bitcoin Core
28.99.0
P2P Digital Currency
src
bench
checkqueue.cpp
Go to the documentation of this file.
1
// Copyright (c) 2015-2022 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 <
checkqueue.h
>
7
#include <
common/system.h
>
8
#include <
key.h
>
9
#include <
prevector.h
>
10
#include <random.h>
11
12
#include <cstddef>
13
#include <cstdint>
14
#include <utility>
15
#include <vector>
16
17
static
const
size_t
BATCHES
= 101;
18
static
const
size_t
BATCH_SIZE
= 30;
19
static
const
int
PREVECTOR_SIZE
= 28;
20
static
const
unsigned
int
QUEUE_BATCH_SIZE
= 128;
21
22
// This Benchmark tests the CheckQueue with a slightly realistic workload,
23
// where checks all contain a prevector that is indirect 50% of the time
24
// and there is a little bit of work done between calls to Add.
25
static
void
CCheckQueueSpeedPrevectorJob
(
benchmark::Bench
& bench)
26
{
27
// We shouldn't ever be running with the checkqueue on a single core machine.
28
if
(
GetNumCores
() <= 1)
return
;
29
30
ECC_Context
ecc_context
{};
31
32
struct
PrevectorJob {
33
prevector<PREVECTOR_SIZE, uint8_t>
p;
34
explicit
PrevectorJob(
FastRandomContext
& insecure_rand){
35
p.
resize
(insecure_rand.
randrange
(
PREVECTOR_SIZE
*2));
36
}
37
std::optional<int> operator()()
38
{
39
return
std::nullopt;
40
}
41
};
42
43
// The main thread should be counted to prevent thread oversubscription, and
44
// to decrease the variance of benchmark results.
45
int
worker_threads_num{
GetNumCores
() - 1};
46
CCheckQueue<PrevectorJob>
queue{
QUEUE_BATCH_SIZE
, worker_threads_num};
47
48
// create all the data once, then submit copies in the benchmark.
49
FastRandomContext
insecure_rand(
true
);
50
std::vector<std::vector<PrevectorJob>> vBatches(
BATCHES
);
51
for
(
auto
& vChecks : vBatches) {
52
vChecks.reserve(
BATCH_SIZE
);
53
for
(
size_t
x = 0; x <
BATCH_SIZE
; ++x)
54
vChecks.emplace_back(insecure_rand);
55
}
56
57
bench.
minEpochIterations
(10).
batch
(
BATCH_SIZE
*
BATCHES
).
unit
(
"job"
).
run
([&] {
58
// Make insecure_rand here so that each iteration is identical.
59
CCheckQueueControl<PrevectorJob>
control(&queue);
60
for
(
auto
vChecks : vBatches) {
61
control.
Add
(std::move(vChecks));
62
}
63
// control waits for completion by RAII, but
64
// it is done explicitly here for clarity
65
control.
Complete
();
66
});
67
}
68
BENCHMARK
(
CCheckQueueSpeedPrevectorJob
,
benchmark::PriorityLevel::HIGH
);
bench.h
BATCH_SIZE
static const size_t BATCH_SIZE
Definition:
checkqueue.cpp:18
CCheckQueueSpeedPrevectorJob
static void CCheckQueueSpeedPrevectorJob(benchmark::Bench &bench)
Definition:
checkqueue.cpp:25
PREVECTOR_SIZE
static const int PREVECTOR_SIZE
Definition:
checkqueue.cpp:19
BENCHMARK
BENCHMARK(CCheckQueueSpeedPrevectorJob, benchmark::PriorityLevel::HIGH)
BATCHES
static const size_t BATCHES
Definition:
checkqueue.cpp:17
QUEUE_BATCH_SIZE
static const unsigned int QUEUE_BATCH_SIZE
Definition:
checkqueue.cpp:20
ecc_context
ECC_Context ecc_context
Definition:
bitcoin-wallet.cpp:135
checkqueue.h
CCheckQueueControl
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
Definition:
checkqueue.h:209
CCheckQueueControl::Complete
std::optional< R > Complete()
Definition:
checkqueue.h:226
CCheckQueueControl::Add
void Add(std::vector< T > &&vChecks)
Definition:
checkqueue.h:234
CCheckQueue
Queue for verifications that have to be performed.
Definition:
checkqueue.h:34
ECC_Context
RAII class initializing and deinitializing global state for elliptic curve support.
Definition:
key.h:322
FastRandomContext
Fast randomness source.
Definition:
random.h:377
RandomMixin::randrange
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
Definition:
random.h:254
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition:
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition:
nanobench.h:1234
ankerl::nanobench::Bench::batch
Bench & batch(T b) noexcept
Sets the batch size.
Definition:
nanobench.h:1258
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
ankerl::nanobench::Bench::minEpochIterations
ANKERL_NANOBENCH(NODISCARD) std Bench & minEpochIterations(uint64_t numIters) noexcept
Sets the minimum number of iterations each epoch should take.
prevector
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition:
prevector.h:37
prevector::resize
void resize(size_type new_size)
Definition:
prevector.h:328
GetNumCores
int GetNumCores()
Return the number of cores available on the current system.
Definition:
system.cpp:103
key.h
benchmark::HIGH
@ HIGH
Definition:
bench.h:48
prevector.h
system.h
Generated on Wed Dec 18 2024 20:00:13 for Bitcoin Core by
1.9.4