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 a little bit of work done between calls to Add.
| 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); |
nothing calls this directly
no test coverage detected