| 119 | }; |
| 120 | |
| 121 | class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 122 | { |
| 123 | public: |
| 124 | using BenchmarkPC::BenchmarkPC; |
| 125 | |
| 126 | protected: |
| 127 | void Initialize(CppBenchmark::ContextPC& context) override |
| 128 | { |
| 129 | _queue = std::make_shared<lock_bounded_queue_t<int>>(queue_bound_size); |
| 130 | _count = 1; |
| 131 | } |
| 132 | |
| 133 | void Cleanup(CppBenchmark::ContextPC& context) override |
| 134 | { |
| 135 | _queue.reset(); |
| 136 | } |
| 137 | |
| 138 | void RunProducer(CppBenchmark::ContextPC& context) override |
| 139 | { |
| 140 | if (_count >= items_to_produce) |
| 141 | { |
| 142 | int value = 0; |
| 143 | _queue->enqueue(value); |
| 144 | context.StopProduce(); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | int value = _count; |
| 149 | _queue->enqueue(value); |
| 150 | ++_count; |
| 151 | } |
| 152 | |
| 153 | void RunConsumer(CppBenchmark::ContextPC& context) override |
| 154 | { |
| 155 | int value = -1; |
| 156 | _queue->dequeue(value); |
| 157 | if (value == 0) |
| 158 | context.StopConsume(); |
| 159 | } |
| 160 | |
| 161 | private: |
| 162 | std::shared_ptr<lock_bounded_queue_t<int>> _queue; |
| 163 | std::atomic<int> _count; |
| 164 | }; |
| 165 | |
| 166 | BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::BlockingConcurrentQueue<int>>, "moodycamel::BlockingConcurrentQueue<int>", settings) |
| 167 | BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::ConcurrentQueue<int>>, "moodycamel::ConcurrentQueueBenchmark<int>", settings) |
nothing calls this directly
no outgoing calls
no test coverage detected