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

Class LockBoundedQueueBenchmark

examples/spsc.cpp:203–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201};
202
203class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
204{
205public:
206 using BenchmarkPC::BenchmarkPC;
207
208protected:
209 void Initialize(CppBenchmark::ContextPC& context) override
210 {
211 _queue = std::make_shared<lock_bounded_queue_t<int>>(queue_bound_size);
212 _count = 1;
213 }
214
215 void Cleanup(CppBenchmark::ContextPC& context) override
216 {
217 _queue.reset();
218 }
219
220 void RunProducer(CppBenchmark::ContextPC& context) override
221 {
222 if (_count >= items_to_produce)
223 {
224 int value = 0;
225 _queue->enqueue(value);
226 context.StopProduce();
227 return;
228 }
229
230 int value = _count;
231 _queue->enqueue(value);
232 ++_count;
233 }
234
235 void RunConsumer(CppBenchmark::ContextPC& context) override
236 {
237 int value = -1;
238 _queue->dequeue(value);
239 if (value == 0)
240 context.StopConsume();
241 }
242
243private:
244 std::shared_ptr<lock_bounded_queue_t<int>> _queue;
245 std::atomic<int> _count;
246};
247
248BENCHMARK_CLASS(ReaderWriterQueueBenchmark<moodycamel::BlockingReaderWriterQueue<int>>, "moodycamel::BlockingReaderWriterQueue<int>", settings)
249BENCHMARK_CLASS(ReaderWriterQueueBenchmark<moodycamel::ReaderWriterQueue<int>>, "moodycamel::ReaderWriterQueue<int>", settings)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected