| 201 | }; |
| 202 | |
| 203 | class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 204 | { |
| 205 | public: |
| 206 | using BenchmarkPC::BenchmarkPC; |
| 207 | |
| 208 | protected: |
| 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 | |
| 243 | private: |
| 244 | std::shared_ptr<lock_bounded_queue_t<int>> _queue; |
| 245 | std::atomic<int> _count; |
| 246 | }; |
| 247 | |
| 248 | BENCHMARK_CLASS(ReaderWriterQueueBenchmark<moodycamel::BlockingReaderWriterQueue<int>>, "moodycamel::BlockingReaderWriterQueue<int>", settings) |
| 249 | BENCHMARK_CLASS(ReaderWriterQueueBenchmark<moodycamel::ReaderWriterQueue<int>>, "moodycamel::ReaderWriterQueue<int>", settings) |
nothing calls this directly
no outgoing calls
no test coverage detected