|
|
@ -15,6 +15,11 @@ |
|
|
|
// This Benchmark tests the CheckQueue with the lightest
|
|
|
|
// This Benchmark tests the CheckQueue with the lightest
|
|
|
|
// weight Checks, so it should make any lock contention
|
|
|
|
// weight Checks, so it should make any lock contention
|
|
|
|
// particularly visible
|
|
|
|
// particularly visible
|
|
|
|
|
|
|
|
static const int MIN_CORES = 2; |
|
|
|
|
|
|
|
static const size_t BATCHES = 101; |
|
|
|
|
|
|
|
static const size_t BATCH_SIZE = 30; |
|
|
|
|
|
|
|
static const int PREVECTOR_SIZE = 28; |
|
|
|
|
|
|
|
static const int QUEUE_BATCH_SIZE = 128; |
|
|
|
static void CCheckQueueSpeed(benchmark::State& state) |
|
|
|
static void CCheckQueueSpeed(benchmark::State& state) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct FakeJobNoWork { |
|
|
|
struct FakeJobNoWork { |
|
|
@ -24,21 +29,25 @@ static void CCheckQueueSpeed(benchmark::State& state) |
|
|
|
} |
|
|
|
} |
|
|
|
void swap(FakeJobNoWork& x){}; |
|
|
|
void swap(FakeJobNoWork& x){}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
CCheckQueue<FakeJobNoWork> queue {128}; |
|
|
|
CCheckQueue<FakeJobNoWork> queue {QUEUE_BATCH_SIZE}; |
|
|
|
boost::thread_group tg; |
|
|
|
boost::thread_group tg; |
|
|
|
for (auto x = 0; x < std::max(2, GetNumCores()); ++x) { |
|
|
|
for (auto x = 0; x < std::max(MIN_CORES, GetNumCores()); ++x) { |
|
|
|
tg.create_thread([&]{queue.Thread();}); |
|
|
|
tg.create_thread([&]{queue.Thread();}); |
|
|
|
} |
|
|
|
} |
|
|
|
while (state.KeepRunning()) { |
|
|
|
while (state.KeepRunning()) { |
|
|
|
CCheckQueueControl<FakeJobNoWork> control(&queue); |
|
|
|
CCheckQueueControl<FakeJobNoWork> control(&queue); |
|
|
|
// We can make vChecks out of the loop because calling Add doesn't
|
|
|
|
|
|
|
|
// change the size of the vector.
|
|
|
|
|
|
|
|
std::vector<FakeJobNoWork> vChecks; |
|
|
|
|
|
|
|
vChecks.resize(30); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We call Add a number of times to simulate the behavior of adding
|
|
|
|
// We call Add a number of times to simulate the behavior of adding
|
|
|
|
// a block of transactions at once.
|
|
|
|
// a block of transactions at once.
|
|
|
|
for (size_t j = 0; j < 101; ++j) { |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::vector<FakeJobNoWork>> vBatches(BATCHES); |
|
|
|
|
|
|
|
for (auto& vChecks : vBatches) { |
|
|
|
|
|
|
|
vChecks.resize(BATCH_SIZE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (auto& vChecks : vBatches) { |
|
|
|
|
|
|
|
// We can't make vChecks in the inner loop because we want to measure
|
|
|
|
|
|
|
|
// the cost of getting the memory to each thread and we might get the same
|
|
|
|
|
|
|
|
// memory
|
|
|
|
control.Add(vChecks); |
|
|
|
control.Add(vChecks); |
|
|
|
} |
|
|
|
} |
|
|
|
// control waits for completion by RAII, but
|
|
|
|
// control waits for completion by RAII, but
|
|
|
@ -55,11 +64,11 @@ static void CCheckQueueSpeed(benchmark::State& state) |
|
|
|
static void CCheckQueueSpeedPrevectorJob(benchmark::State& state) |
|
|
|
static void CCheckQueueSpeedPrevectorJob(benchmark::State& state) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct PrevectorJob { |
|
|
|
struct PrevectorJob { |
|
|
|
prevector<28, uint8_t> p; |
|
|
|
prevector<PREVECTOR_SIZE, uint8_t> p; |
|
|
|
PrevectorJob(){ |
|
|
|
PrevectorJob(){ |
|
|
|
} |
|
|
|
} |
|
|
|
PrevectorJob(FastRandomContext& insecure_rand){ |
|
|
|
PrevectorJob(FastRandomContext& insecure_rand){ |
|
|
|
p.resize(insecure_rand.rand32() % 56); |
|
|
|
p.resize(insecure_rand.rand32() % (PREVECTOR_SIZE*2)); |
|
|
|
} |
|
|
|
} |
|
|
|
bool operator()() |
|
|
|
bool operator()() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -67,19 +76,19 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::State& state) |
|
|
|
} |
|
|
|
} |
|
|
|
void swap(PrevectorJob& x){p.swap(x.p);}; |
|
|
|
void swap(PrevectorJob& x){p.swap(x.p);}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
CCheckQueue<PrevectorJob> queue {128}; |
|
|
|
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE}; |
|
|
|
boost::thread_group tg; |
|
|
|
boost::thread_group tg; |
|
|
|
for (auto x = 0; x < std::max(2, GetNumCores()); ++x) { |
|
|
|
for (auto x = 0; x < std::max(MIN_CORES, GetNumCores()); ++x) { |
|
|
|
tg.create_thread([&]{queue.Thread();}); |
|
|
|
tg.create_thread([&]{queue.Thread();}); |
|
|
|
} |
|
|
|
} |
|
|
|
while (state.KeepRunning()) { |
|
|
|
while (state.KeepRunning()) { |
|
|
|
// Make insecure_rand here so that each iteration is identical.
|
|
|
|
// Make insecure_rand here so that each iteration is identical.
|
|
|
|
FastRandomContext insecure_rand(true); |
|
|
|
FastRandomContext insecure_rand(true); |
|
|
|
CCheckQueueControl<PrevectorJob> control(&queue); |
|
|
|
CCheckQueueControl<PrevectorJob> control(&queue); |
|
|
|
for (size_t j = 0; j < 101; ++j) { |
|
|
|
std::vector<std::vector<PrevectorJob>> vBatches(BATCHES); |
|
|
|
std::vector<PrevectorJob> vChecks; |
|
|
|
for (auto& vChecks : vBatches) { |
|
|
|
vChecks.reserve(30); |
|
|
|
vChecks.reserve(BATCH_SIZE); |
|
|
|
for (auto x = 0; x < 30; ++x) |
|
|
|
for (size_t x = 0; x < BATCH_SIZE; ++x) |
|
|
|
vChecks.emplace_back(insecure_rand); |
|
|
|
vChecks.emplace_back(insecure_rand); |
|
|
|
control.Add(vChecks); |
|
|
|
control.Add(vChecks); |
|
|
|
} |
|
|
|
} |
|
|
|