1 // Copyright (c) 2015-2017 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.
5 #include <bench/bench.h>
7 #include <validation.h>
8 #include <checkqueue.h>
11 #include <boost/thread/thread.hpp>
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 unsigned int QUEUE_BATCH_SIZE
= 128;
21 // This Benchmark tests the CheckQueue with a slightly realistic workload,
22 // where checks all contain a prevector that is indirect 50% of the time
23 // and there is a little bit of work done between calls to Add.
24 static void CCheckQueueSpeedPrevectorJob(benchmark::State
& state
)
27 prevector
<PREVECTOR_SIZE
, uint8_t> p
;
30 explicit PrevectorJob(FastRandomContext
& insecure_rand
){
31 p
.resize(insecure_rand
.randrange(PREVECTOR_SIZE
*2));
37 void swap(PrevectorJob
& x
){p
.swap(x
.p
);};
39 CCheckQueue
<PrevectorJob
> queue
{QUEUE_BATCH_SIZE
};
40 boost::thread_group tg
;
41 for (auto x
= 0; x
< std::max(MIN_CORES
, GetNumCores()); ++x
) {
42 tg
.create_thread([&]{queue
.Thread();});
44 while (state
.KeepRunning()) {
45 // Make insecure_rand here so that each iteration is identical.
46 FastRandomContext
insecure_rand(true);
47 CCheckQueueControl
<PrevectorJob
> control(&queue
);
48 std::vector
<std::vector
<PrevectorJob
>> vBatches(BATCHES
);
49 for (auto& vChecks
: vBatches
) {
50 vChecks
.reserve(BATCH_SIZE
);
51 for (size_t x
= 0; x
< BATCH_SIZE
; ++x
)
52 vChecks
.emplace_back(insecure_rand
);
55 // control waits for completion by RAII, but
56 // it is done explicitly here for clarity
62 BENCHMARK(CCheckQueueSpeedPrevectorJob
, 1400);