Fabcoin Core
0.16.2
P2P Digital Currency
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
src
bench
checkqueue.cpp
Go to the documentation of this file.
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.
4
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
>
13
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
unsigned
int
QUEUE_BATCH_SIZE = 128;
20
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)
25
{
26
struct
PrevectorJob {
27
prevector<PREVECTOR_SIZE, uint8_t>
p;
28
PrevectorJob(){
29
}
30
explicit
PrevectorJob(
FastRandomContext
& insecure_rand){
31
p.
resize
(insecure_rand.
randrange
(PREVECTOR_SIZE*2));
32
}
33
bool
operator()()
34
{
35
return
true
;
36
}
37
void
swap
(PrevectorJob&
x
){p.
swap
(x.p);};
38
};
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();});
43
}
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);
54
}
55
// control waits for completion by RAII, but
56
// it is done explicitly here for clarity
57
control.Wait();
58
}
59
tg.interrupt_all();
60
tg.join_all();
61
}
62
BENCHMARK
(CCheckQueueSpeedPrevectorJob, 1400);
prevector::resize
void resize(size_type new_size)
Definition:
prevector.h:316
std::swap
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Definition:
Interface.h:284
prevector.h
FastRandomContext::randrange
uint64_t randrange(uint64_t range)
Generate a random integer in the range [0..range).
Definition:
random.h:103
benchmark::State::KeepRunning
bool KeepRunning()
Definition:
bench.h:70
CCheckQueueControl
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
Definition:
checkqueue.h:17
x
#define x(i)
prevector::swap
void swap(prevector< N, T, Size, Diff > &other)
Definition:
prevector.h:440
FastRandomContext
Fast randomness source.
Definition:
random.h:44
CCheckQueue
Queue for verifications that have to be performed.
Definition:
checkqueue.h:30
BENCHMARK
BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400)
prevector
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition:
prevector.h:36
bench.h
checkqueue.h
benchmark::State
Definition:
bench.h:54
random.h
std::max
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
Definition:
Common.h:326
GetNumCores
int GetNumCores()
Return the number of physical cores available on the current system.
Definition:
util.cpp:959
Generated on Mon Oct 22 2018 15:15:26 for Fabcoin Core by
1.8.11