MCPcopy Create free account
hub / github.com/chronoxor/CppBenchmark / MPSCQueueBenchmark

Class MPSCQueueBenchmark

examples/mpsc.cpp:77–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75};
76
77class MPSCQueueBenchmark : public CppBenchmark::BenchmarkPC
78{
79public:
80 using BenchmarkPC::BenchmarkPC;
81
82protected:
83 void Initialize(CppBenchmark::ContextPC& context) override
84 {
85 _queue = std::make_shared<mpsc_queue_t<int>>();
86 _count = 1;
87 }
88
89 void Cleanup(CppBenchmark::ContextPC& context) override
90 {
91 _queue.reset();
92 }
93
94 void RunProducer(CppBenchmark::ContextPC& context) override
95 {
96 if (_count >= items_to_produce)
97 {
98 _queue->enqueue(0);
99 context.StopProduce();
100 return;
101 }
102
103 _queue->enqueue(_count++);
104 }
105
106 void RunConsumer(CppBenchmark::ContextPC& context) override
107 {
108 int value = -1;
109 if (_queue->dequeue(value) && (value == 0))
110 context.StopConsume();
111 }
112
113private:
114 std::shared_ptr<mpsc_queue_t<int>> _queue;
115 std::atomic<int> _count;
116};
117
118class MPMCBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
119{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected