MCPcopy Create free account
hub / github.com/chronoxor/CppBenchmark / LockBoundedQueueBenchmark

Class LockBoundedQueueBenchmark

examples/mpmc.cpp:121–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119};
120
121class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
122{
123public:
124 using BenchmarkPC::BenchmarkPC;
125
126protected:
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
161private:
162 std::shared_ptr<lock_bounded_queue_t<int>> _queue;
163 std::atomic<int> _count;
164};
165
166BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::BlockingConcurrentQueue<int>>, "moodycamel::BlockingConcurrentQueue<int>", settings)
167BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::ConcurrentQueue<int>>, "moodycamel::ConcurrentQueueBenchmark<int>", settings)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected