--- /dev/null
+#include <folly/concurrency/UnboundedQueue.h>
+
+#include <chrono>
+#include <cassert>
+#include <iostream>
+#include <memory>
+
+namespace {
+
+const char* kTestName = "EnqueueDequeue";
+size_t kEnqueueStride = 10000;
+
+size_t kUSPSCQueueEnqueueCount = 1200000000;
+const char* kUSPSCQueueBenchmarkName = "FollyUSPSCQueue";
+
+size_t kUMPSCQueueEnqueueCount = 320000000;
+const char* kUMPSCQueueBenchmarkName = "FollyUMPSCQueue";
+
+size_t kUSPMCQueueEnqueueCount = 320000000;
+const char* kUSPMCQueueBenchmarkName = "FollyUSPMCQueue";
+
+size_t kUMPMCQueueEnqueueCount = 320000000;
+const char* kUMPMCQueueBenchmarkName = "FollyMPMCQueue";
+
+typedef folly::USPSCQueue<size_t, false> USPSCQueue;
+typedef folly::UMPSCQueue<size_t, false> UMPSCQueue;
+typedef folly::USPMCQueue<size_t, false> USPMCQueue;
+typedef folly::UMPMCQueue<size_t, false> UMPMCQueue;
+
+}
+
+template <typename Queue>
+void run_queue(size_t enqueue_count, const char* bench_name) {
+ std::cout << "[ RUN ] " << kTestName << "." << bench_name << std::endl;
+ auto start_time = std::chrono::system_clock::now();
+
+ size_t nNo = 0;
+ size_t push_failure = 0;
+ size_t pop_sum = 0;
+ std::unique_ptr<Queue> q(new Queue());
+ while (nNo < enqueue_count) {
+ size_t curr_push_count =
+ std::min(enqueue_count - nNo, kEnqueueStride);
+ for (size_t i = 0; i < curr_push_count; i++) {
+ q->enqueue(nNo++);
+ }
+ size_t res;
+ for (size_t i = 0; i < curr_push_count; i++) {
+ q->dequeue(res);
+ pop_sum += res;
+ }
+ }
+
+ auto finish_time = std::chrono::system_clock::now();
+ auto dur = finish_time - start_time;
+ auto milisecs = std::chrono::duration_cast<std::chrono::milliseconds>(dur);
+
+ size_t supposed_sum = enqueue_count * (enqueue_count - 1) / 2;
+ if (pop_sum != supposed_sum) {
+ std::cout << "Sequential queue pop sum: " << pop_sum
+ << " != " << supposed_sum << "\n";
+ std::cout << "[ FAILED ] " << kTestName << "." << bench_name
+ << " (" << milisecs.count() << " ms)" << std::endl;
+ assert(false && "Folly unbounded queue ERROR");
+ } else {
+ std::cout << "[ OK ] " << kTestName << "." << bench_name
+ << " (" << milisecs.count() << " ms)" << std::endl;
+ }
+}
+
+int main() {
+ run_queue<USPSCQueue>(kUSPSCQueueEnqueueCount, kUSPSCQueueBenchmarkName);
+ run_queue<UMPSCQueue>(kUMPSCQueueEnqueueCount, kUMPSCQueueBenchmarkName);
+ run_queue<USPMCQueue>(kUSPMCQueueEnqueueCount, kUSPMCQueueBenchmarkName);
+ run_queue<UMPMCQueue>(kUMPMCQueueEnqueueCount, kUMPMCQueueBenchmarkName);
+
+ return 0;
+}