Bitcoin ABC
0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
src
bench
checkqueue.cpp
Go to the documentation of this file.
1
// Copyright (c) 2015 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 <
pubkey.h
>
11
#include <
random.h
>
12
13
#include <vector>
14
15
static
const
int
MIN_CORES
= 2;
16
static
const
size_t
BATCHES
= 101;
17
static
const
size_t
BATCH_SIZE
= 30;
18
static
const
int
PREVECTOR_SIZE
= 28;
19
static
const
size_t
QUEUE_BATCH_SIZE
= 128;
20
21
// This Benchmark tests the CheckQueue with a slightly realistic workload, where
22
// checks all contain a prevector that is indirect 50% of the time and there is
23
// a little bit of work done between calls to Add.
24
static
void
CCheckQueueSpeedPrevectorJob
(
benchmark::Bench
&
bench
) {
25
const
ECCVerifyHandle
verify_handle
;
26
ECC_Start
();
27
28
struct
PrevectorJob
{
29
prevector<PREVECTOR_SIZE, uint8_t>
p
;
30
explicit
PrevectorJob
(
FastRandomContext
&insecure_rand) {
31
p
.
resize
(insecure_rand.
randrange
(
PREVECTOR_SIZE
* 2));
32
}
33
bool
operator()() {
return
true
; }
34
};
35
CCheckQueue<PrevectorJob>
queue{
QUEUE_BATCH_SIZE
};
36
queue.
StartWorkerThreads
(std::max(
MIN_CORES
,
GetNumCores
()));
37
38
// create all the data once, then submit copies in the benchmark.
39
FastRandomContext
insecure_rand(
true
);
40
std::vector<std::vector<PrevectorJob>>
vBatches
(
BATCHES
);
41
for
(
auto
&
vChecks
:
vBatches
) {
42
vChecks
.reserve(
BATCH_SIZE
);
43
for
(
size_t
x = 0; x <
BATCH_SIZE
; ++x) {
44
vChecks
.emplace_back(insecure_rand);
45
}
46
}
47
48
bench
.minEpochIterations(10)
49
.batch(
BATCH_SIZE
*
BATCHES
)
50
.unit(
"job"
)
51
.run([&] {
52
// Make insecure_rand here so that each iteration is identical.
53
CCheckQueueControl<PrevectorJob>
control
(&queue);
54
std::vector<std::vector<PrevectorJob>>
vBatches
(
BATCHES
);
55
for
(
auto
&
vChecks
:
vBatches
) {
56
control
.Add(std::move(
vChecks
));
57
}
58
// control waits for completion by RAII, but it is done explicitly
59
// here for clarity
60
control
.Wait();
61
});
62
queue.StopWorkerThreads();
63
ECC_Stop
();
64
}
65
BENCHMARK
(
CCheckQueueSpeedPrevectorJob
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:65
MIN_CORES
static const int MIN_CORES
Definition
checkqueue.cpp:15
BATCH_SIZE
static const size_t BATCH_SIZE
Definition
checkqueue.cpp:17
CCheckQueueSpeedPrevectorJob
static void CCheckQueueSpeedPrevectorJob(benchmark::Bench &bench)
Definition
checkqueue.cpp:24
PREVECTOR_SIZE
static const int PREVECTOR_SIZE
Definition
checkqueue.cpp:18
BATCHES
static const size_t BATCHES
Definition
checkqueue.cpp:16
QUEUE_BATCH_SIZE
static const size_t QUEUE_BATCH_SIZE
Definition
checkqueue.cpp:19
checkqueue.h
CCheckQueueControl
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
Definition
checkqueue.h:198
CCheckQueue
Queue for verifications that have to be performed.
Definition
checkqueue.h:28
CCheckQueue::StartWorkerThreads
void StartWorkerThreads(const int threads_num) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Create a pool of new worker threads.
Definition
checkqueue.h:144
ECCVerifyHandle
Users of this module must hold an ECCVerifyHandle.
Definition
pubkey.h:223
FastRandomContext
Fast randomness source.
Definition
random.h:156
FastRandomContext::randrange
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
Definition
random.h:231
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:616
prevector
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition
prevector.h:38
prevector::resize
void resize(size_type new_size)
Definition
prevector.h:424
ECC_Start
void ECC_Start()
Initialize the elliptic curve support.
Definition
key.cpp:434
ECC_Stop
void ECC_Stop()
Deinitialize the elliptic curve support.
Definition
key.cpp:451
key.h
prevector.h
pubkey.h
random.h
GetRand
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition
random.h:85
GetNumCores
int GetNumCores()
Return the number of cores available on the current system.
Definition
system.cpp:111
system.h
Generated on Sat Nov 23 2024 02:37:58 for Bitcoin ABC by
1.9.8