Changeset View
Changeset View
Standalone View
Standalone View
src/bench/checkqueue.cpp
// Copyright (c) 2015 The Bitcoin Core developers | // Copyright (c) 2015 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <checkqueue.h> | #include <checkqueue.h> | ||||
#include <key.h> | |||||
#include <prevector.h> | #include <prevector.h> | ||||
#include <pubkey.h> | |||||
#include <random.h> | #include <random.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <boost/thread/thread.hpp> | #include <boost/thread/thread.hpp> | ||||
#include <vector> | #include <vector> | ||||
static const int MIN_CORES = 2; | static const int MIN_CORES = 2; | ||||
static const size_t BATCHES = 101; | static const size_t BATCHES = 101; | ||||
static const size_t BATCH_SIZE = 30; | static const size_t BATCH_SIZE = 30; | ||||
static const int PREVECTOR_SIZE = 28; | static const int PREVECTOR_SIZE = 28; | ||||
static const size_t QUEUE_BATCH_SIZE = 128; | static const size_t QUEUE_BATCH_SIZE = 128; | ||||
// This Benchmark tests the CheckQueue with a slightly realistic workload, where | // This Benchmark tests the CheckQueue with a slightly realistic workload, where | ||||
// checks all contain a prevector that is indirect 50% of the time and there is | // checks all contain a prevector that is indirect 50% of the time and there is | ||||
// a little bit of work done between calls to Add. | // a little bit of work done between calls to Add. | ||||
static void CCheckQueueSpeedPrevectorJob(benchmark::State &state) { | static void CCheckQueueSpeedPrevectorJob(benchmark::State &state) { | ||||
const ECCVerifyHandle verify_handle; | |||||
ECC_Start(); | |||||
struct PrevectorJob { | struct PrevectorJob { | ||||
prevector<PREVECTOR_SIZE, uint8_t> p; | prevector<PREVECTOR_SIZE, uint8_t> p; | ||||
PrevectorJob() {} | PrevectorJob() {} | ||||
explicit PrevectorJob(FastRandomContext &insecure_rand) { | explicit PrevectorJob(FastRandomContext &insecure_rand) { | ||||
p.resize(insecure_rand.randrange(PREVECTOR_SIZE * 2)); | p.resize(insecure_rand.randrange(PREVECTOR_SIZE * 2)); | ||||
} | } | ||||
bool operator()() { return true; } | bool operator()() { return true; } | ||||
void swap(PrevectorJob &x) { p.swap(x.p); }; | void swap(PrevectorJob &x) { p.swap(x.p); }; | ||||
Show All 16 Lines | while (state.KeepRunning()) { | ||||
control.Add(vChecks); | control.Add(vChecks); | ||||
} | } | ||||
// control waits for completion by RAII, but it is done explicitly here | // control waits for completion by RAII, but it is done explicitly here | ||||
// for clarity | // for clarity | ||||
control.Wait(); | control.Wait(); | ||||
} | } | ||||
tg.interrupt_all(); | tg.interrupt_all(); | ||||
tg.join_all(); | tg.join_all(); | ||||
ECC_Stop(); | |||||
} | } | ||||
BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400); | BENCHMARK(CCheckQueueSpeedPrevectorJob, 1400); |