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

Class MPMCBoundedQueueBenchmark

examples/mpsc.cpp:118–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116};
117
118class MPMCBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
119{
120public:
121 using BenchmarkPC::BenchmarkPC;
122
123protected:
124 void Initialize(CppBenchmark::ContextPC& context) override
125 {
126 _queue = std::make_shared<mpmc_bounded_queue_t<int>>(queue_bound_size);
127 _count = 1;
128 }
129
130 void Cleanup(CppBenchmark::ContextPC& context) override
131 {
132 _queue.reset();
133 }
134
135 void RunProducer(CppBenchmark::ContextPC& context) override
136 {
137 if (_count >= items_to_produce)
138 {
139 int value = 0;
140 if (_queue->enqueue(value))
141 context.StopProduce();
142 return;
143 }
144
145 int value = _count;
146 if (_queue->enqueue(value))
147 ++_count;
148 }
149
150 void RunConsumer(CppBenchmark::ContextPC& context) override
151 {
152 int value = -1;
153 if (_queue->dequeue(value) && (value == 0))
154 context.StopConsume();
155 }
156
157private:
158 std::shared_ptr<mpmc_bounded_queue_t<int>> _queue;
159 std::atomic<int> _count;
160};
161
162class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
163{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected