MCPcopy Create free account
hub / github.com/ElementsProject/elements / CCheckQueueSpeedPrevectorJob

Function CCheckQueueSpeedPrevectorJob

src/bench/checkqueue.cpp:23–78  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

21// where checks all contain a prevector that is indirect 50% of the time
22// and there is a little bit of work done between calls to Add.
23static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
24{
25 // We shouldn't ever be running with the checkqueue on a single core machine.
26 if (GetNumCores() <= 1) return;
27
28 const ECCVerifyHandle verify_handle;
29 ECC_Start();
30
31 struct PrevectorJob {
32 prevector<PREVECTOR_SIZE, uint8_t> p;
33 // ELEMENTS: fix unused member function warnings
34 // PrevectorJob(){
35 // }
36 explicit PrevectorJob(FastRandomContext& insecure_rand){
37 p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
38 }
39 bool operator()()
40 {
41 return true;
42 }
43 // void swap(PrevectorJob& x){p.swap(x.p);};
44 };
45 CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};
46 // The main thread should be counted to prevent thread oversubscription, and
47 // to decrease the variance of benchmark results.
48 queue.StartWorkerThreads(GetNumCores() - 1);
49
50 // create all the data once, then submit copies in the benchmark.
51 FastRandomContext insecure_rand(true);
52 std::vector<std::vector<PrevectorJob*>> vBatches(BATCHES);
53 for (auto& vChecks : vBatches) {
54 vChecks.reserve(BATCH_SIZE);
55 // ELEMENTS: allocate new jobs...
56 for (size_t x = 0; x < BATCH_SIZE; ++x)
57 vChecks[x] = new PrevectorJob(insecure_rand);
58 }
59
60 bench.minEpochIterations(10).batch(BATCH_SIZE * BATCHES).unit("job").run([&] {
61 // Make insecure_rand here so that each iteration is identical.
62 CCheckQueueControl<PrevectorJob> control(&queue);
63 for (auto vChecks : vBatches) {
64 control.Add(vChecks);
65 }
66 // control waits for completion by RAII, but
67 // it is done explicitly here for clarity
68 control.Wait();
69 });
70 queue.StopWorkerThreads();
71
72 // ELEMENTS: ...and deallocate them
73 for (auto& vChecks : vBatches)
74 for (size_t x = 0; x < BATCH_SIZE; ++x)
75 delete vChecks[x];
76
77 ECC_Stop();
78}
79BENCHMARK(CCheckQueueSpeedPrevectorJob);

Callers

nothing calls this directly

Calls 11

GetNumCoresFunction · 0.85
ECC_StartFunction · 0.85
ECC_StopFunction · 0.85
StartWorkerThreadsMethod · 0.80
minEpochIterationsMethod · 0.80
StopWorkerThreadsMethod · 0.80
reserveMethod · 0.45
runMethod · 0.45
batchMethod · 0.45
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected