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

Class LockBoundedQueueBenchmark

examples/mpsc.cpp:162–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160};
161
162class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC
163{
164public:
165 using BenchmarkPC::BenchmarkPC;
166
167protected:
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
202private:
203 std::shared_ptr<lock_bounded_queue_t<int>> _queue;
204 std::atomic<int> _count;
205};
206
207BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::BlockingConcurrentQueue<int>>, "moodycamel::BlockingConcurrentQueue<int>", settings)
208BENCHMARK_CLASS(ConcurrentQueueBenchmark<moodycamel::ConcurrentQueue<int>>, "moodycamel::ConcurrentQueueBenchmark<int>", settings)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected