| 75 | }; |
| 76 | |
| 77 | class MPSCQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 78 | { |
| 79 | public: |
| 80 | using BenchmarkPC::BenchmarkPC; |
| 81 | |
| 82 | protected: |
| 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 | |
| 113 | private: |
| 114 | std::shared_ptr<mpsc_queue_t<int>> _queue; |
| 115 | std::atomic<int> _count; |
| 116 | }; |
| 117 | |
| 118 | class MPMCBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 119 | { |
nothing calls this directly
no outgoing calls
no test coverage detected