Merge #11997: [tests] util_tests.cpp: actually check ignored args
[bitcoinplatinum.git] / src / bench / checkqueue.cpp
blob6e816f1beced9c125a51e1e5e47fe7d4d70ea8fc
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>
6 #include <util.h>
7 #include <validation.h>
8 #include <checkqueue.h>
9 #include <prevector.h>
10 #include <vector>
11 #include <boost/thread/thread.hpp>
12 #include <random.h>
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)
26 struct PrevectorJob {
27 prevector<PREVECTOR_SIZE, uint8_t> p;
28 PrevectorJob(){
30 explicit PrevectorJob(FastRandomContext& insecure_rand){
31 p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
33 bool operator()()
35 return true;
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);
53 control.Add(vChecks);
55 // control waits for completion by RAII, but
56 // it is done explicitly here for clarity
57 control.Wait();
59 tg.interrupt_all();
60 tg.join_all();
62 BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400);