| 160 | }; |
| 161 | |
| 162 | class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 163 | { |
| 164 | public: |
| 165 | using BenchmarkPC::BenchmarkPC; |
| 166 | |
| 167 | protected: |
| 168 | void Initialize(CppBenchmark::ContextPC& context) override |
| 169 | { |
| 170 | _queue = std::make_shared<lock_bounded_queue_t<int>>(queue_bound_size); |
| 171 | _count = 1; |
| 172 | } |
| 173 | |
| 174 | void Cleanup(CppBenchmark::ContextPC& context) override |
| 175 | { |
| 176 | _queue.reset(); |
| 177 | } |
| 178 | |
| 179 | void RunProducer(CppBenchmark::ContextPC& context) override |
| 180 | { |
| 181 | if (_count >= items_to_produce) |
| 182 | { |
| 183 | int value = 0; |
| 184 | _queue->enqueue(value); |
| 185 | context.StopProduce(); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | int value = _count; |
| 190 | _queue->enqueue(value); |
| 191 | ++_count; |
| 192 | } |
| 193 | |
| 194 | void RunConsumer(CppBenchmark::ContextPC& context) override |
| 195 | { |
| 196 | int value = -1; |
| 197 | _queue->dequeue(value); |
| 198 | if (value == 0) |
| 199 | context.StopConsume(); |
| 200 | } |
| 201 | |
| 202 | private: |
| 203 | std::shared_ptr<lock_bounded_queue_t<int>> _queue; |
| 204 | std::atomic<int> _count; |
| 205 | }; |
| 206 | |
| 207 | BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::BlockingConcurrentQueue<int>>, "moodycamel::BlockingConcurrentQueue<int>", settings) |
| 208 | BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::ConcurrentQueue<int>>, "moodycamel::ConcurrentQueueBenchmark<int>", settings) |
nothing calls this directly
no outgoing calls
no test coverage detected