-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
48 lines (37 loc) · 1.16 KB
/
Copy pathbenchmark.cpp
File metadata and controls
48 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "include/spsc_queue.hpp"
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
using namespace std::chrono;
struct DummyMsg {
uint64_t data[8];
};
void run_spsc_benchmark() {
SPSCQueue<DummyMsg, 65536> queue;
const uint64_t MSG_COUNT = 10'000'000;
std::atomic<bool> start_flag{false};
std::thread consumer([&]() {
DummyMsg msg;
while (!start_flag.load(std::memory_order_acquire)) {}
for (uint64_t i = 0; i < MSG_COUNT; ++i) {
while (!queue.pop(msg)) {}
}
});
DummyMsg msg{};
start_flag.store(true, std::memory_order_release);
auto t0 = high_resolution_clock::now();
for (uint64_t i = 0; i < MSG_COUNT; ++i) {
while (!queue.push(msg)) {}
}
consumer.join();
auto t1 = high_resolution_clock::now();
double elapsed = duration_cast<duration<double>>(t1 - t0).count();
std::cout << "[Benchmark] SPSCQueue Throughput: "
<< (MSG_COUNT / elapsed) / 1e6 << " million msgs/sec\n";
}
int main() {
std::cout << "Running SPSCQueue Throughput Benchmark...\n";
run_spsc_benchmark();
return 0;
}