#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4127)
#pragma warning(disable: 4702)
#endif
#include "cameron/readerwriterqueue.h"
#include "folly/ProducerConsumerQueue.h"
#include "lockfree/lock-bounded-queue.hpp"
#include "lockfree/spsc-queue.hpp"
#include "lockfree/spsc-bounded-queue.hpp"
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif
#include <atomic>
#include <memory>
const int queue_bound_size = 65536;
const int items_to_produce = 10000000;
template <class TReaderWriterQueue>
{
public:
protected:
{
_queue = std::make_shared<TReaderWriterQueue>();
_count = 1;
}
{
_queue.reset();
}
{
if (_count >= items_to_produce)
{
if (_queue->try_enqueue(0))
return;
}
if (_queue->try_enqueue(_count))
++_count;
}
{
int value = -1;
if (_queue->try_dequeue(value) && (value == 0))
}
private:
std::shared_ptr<TReaderWriterQueue> _queue;
std::atomic<int> _count;
};
{
public:
protected:
{
_queue = std::make_shared<folly::ProducerConsumerQueue<int>>(queue_bound_size);
_count = 1;
}
{
_queue.reset();
}
{
if (_count >= items_to_produce)
{
if (_queue->write(0))
return;
}
if (_queue->write(_count))
++_count;
}
{
int value = -1;
if (_queue->read(value) && (value == 0))
}
private:
std::shared_ptr<folly::ProducerConsumerQueue<int>> _queue;
std::atomic<int> _count;
};
{
public:
protected:
{
_queue = std::make_shared<spsc_queue_t<int>>();
_count = 1;
}
{
_queue.reset();
}
{
if (_count >= items_to_produce)
{
_queue->enqueue(0);
return;
}
_queue->enqueue(_count++);
}
{
int value = -1;
if (_queue->dequeue(value) && (value == 0))
}
private:
std::shared_ptr<spsc_queue_t<int>> _queue;
std::atomic<int> _count;
};
{
public:
protected:
{
_queue = std::make_shared<spsc_bounded_queue_t<int>>(queue_bound_size);
_count = 1;
}
{
_queue.reset();
}
{
if (_count >= items_to_produce)
{
int value = 0;
if (_queue->enqueue(value))
return;
}
int value = _count;
if (_queue->enqueue(value))
++_count;
}
{
int value = -1;
if (_queue->dequeue(value) && (value == 0))
}
private:
std::shared_ptr<spsc_bounded_queue_t<int>> _queue;
std::atomic<int> _count;
};
{
public:
protected:
{
_queue = std::make_shared<lock_bounded_queue_t<int>>(queue_bound_size);
_count = 1;
}
{
_queue.reset();
}
{
if (_count >= items_to_produce)
{
int value = 0;
_queue->enqueue(value);
return;
}
int value = _count;
_queue->enqueue(value);
++_count;
}
{
int value = -1;
_queue->dequeue(value);
if (value == 0)
}
private:
std::shared_ptr<lock_bounded_queue_t<int>> _queue;
std::atomic<int> _count;
};
BENCHMARK_CLASS(ReaderWriterQueueBenchmark<moodycamel::BlockingReaderWriterQueue<int>>,
"moodycamel::BlockingReaderWriterQueue<int>", settings)
BENCHMARK_CLASS(ReaderWriterQueueBenchmark<moodycamel::ReaderWriterQueue<int>>,
"moodycamel::ReaderWriterQueue<int>", settings)
BENCHMARK_CLASS(ProducerConsumerQueueBenchmark,
"folly::ProducerConsumerQueue<int>", settings)
BENCHMARK_CLASS(SPSCQueueBenchmark,
"lockfree::spsc_queue_t<int>", settings)
BENCHMARK_CLASS(SPSCBoundedQueueBenchmark,
"lockfree::spsc_bounded_queue_t<int>", settings)
BENCHMARK_CLASS(LockBoundedQueueBenchmark,
"lockfree::lock_bounded_queue_t<int>", settings)
Producers/Consumers benchmark base class.
BenchmarkPC(const std::string &name, Types... settings)
Default class constructor.
virtual void RunConsumer(ContextPC &context)=0
Consumer run method.
virtual void RunProducer(ContextPC &context)=0
Producer run method.
Benchmark producer/consumer running context.
void StopConsume() noexcept
Stop benchmark consumption.
void StopProduce() noexcept
Stop benchmark production.
virtual void Initialize(ContextPC &context)
Initialize benchmark.
virtual void Cleanup(ContextPC &context)
Cleanup benchmark.
Settings & PC(int producers, int consumers)
Add new producers/consumers count to the benchmark running plan.
Settings & Infinite()
Set infinite benchmark operations flag.
CppBenchmark definitions.
#define BENCHMARK_CLASS(type,...)
Benchmark class register macro.
#define BENCHMARK_MAIN()
Benchmark main entry point macro.