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

Class SPSCBoundedQueueBenchmark

examples/spsc.cpp:159–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157};
158
159class SPSCBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
160{
161public:
162 using BenchmarkPC::BenchmarkPC;
163
164protected:
165 void Initialize(CppBenchmark::ContextPC& context) override
166 {
167 _queue = std::make_shared<spsc_bounded_queue_t<int>>(queue_bound_size);
168 _count = 1;
169 }
170
171 void Cleanup(CppBenchmark::ContextPC& context) override
172 {
173 _queue.reset();
174 }
175
176 void RunProducer(CppBenchmark::ContextPC& context) override
177 {
178 if (_count >= items_to_produce)
179 {
180 int value = 0;
181 if (_queue->enqueue(value))
182 context.StopProduce();
183 return;
184 }
185
186 int value = _count;
187 if (_queue->enqueue(value))
188 ++_count;
189 }
190
191 void RunConsumer(CppBenchmark::ContextPC& context) override
192 {
193 int value = -1;
194 if (_queue->dequeue(value) && (value == 0))
195 context.StopConsume();
196 }
197
198private:
199 std::shared_ptr<spsc_bounded_queue_t<int>> _queue;
200 std::atomic<int> _count;
201};
202
203class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
204{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected