| 74 | }; |
| 75 | |
| 76 | class ProducerConsumerQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 77 | { |
| 78 | public: |
| 79 | using BenchmarkPC::BenchmarkPC; |
| 80 | |
| 81 | protected: |
| 82 | void Initialize(CppBenchmark::ContextPC& context) override |
| 83 | { |
| 84 | _queue = std::make_shared<folly::ProducerConsumerQueue<int>>(queue_bound_size); |
| 85 | _count = 1; |
| 86 | } |
| 87 | |
| 88 | void Cleanup(CppBenchmark::ContextPC& context) override |
| 89 | { |
| 90 | _queue.reset(); |
| 91 | } |
| 92 | |
| 93 | void RunProducer(CppBenchmark::ContextPC& context) override |
| 94 | { |
| 95 | if (_count >= items_to_produce) |
| 96 | { |
| 97 | if (_queue->write(0)) |
| 98 | context.StopProduce(); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | if (_queue->write(_count)) |
| 103 | ++_count; |
| 104 | } |
| 105 | |
| 106 | void RunConsumer(CppBenchmark::ContextPC& context) override |
| 107 | { |
| 108 | int value = -1; |
| 109 | if (_queue->read(value) && (value == 0)) |
| 110 | context.StopConsume(); |
| 111 | } |
| 112 | |
| 113 | private: |
| 114 | std::shared_ptr<folly::ProducerConsumerQueue<int>> _queue; |
| 115 | std::atomic<int> _count; |
| 116 | }; |
| 117 | |
| 118 | class SPSCQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 119 | { |
nothing calls this directly
no outgoing calls
no test coverage detected