2017-10-19 19:03:05 +08:00
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
#include <benchmark/benchmark_api.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "data_structures/ring_buffer.hpp"
|
|
|
|
|
|
|
|
class RingBufferMultiThreaded : public benchmark::Fixture {
|
|
|
|
protected:
|
2017-11-02 19:02:23 +08:00
|
|
|
RingBuffer<int> buffer{1024};
|
2017-10-19 19:03:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
BENCHMARK_DEFINE_F(RingBufferMultiThreaded, MT)(benchmark::State &st) {
|
|
|
|
while (st.KeepRunning()) {
|
|
|
|
buffer.emplace(42);
|
|
|
|
buffer.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK_REGISTER_F(RingBufferMultiThreaded, MT)->Threads(1);
|
|
|
|
BENCHMARK_REGISTER_F(RingBufferMultiThreaded, MT)->Threads(4);
|
|
|
|
BENCHMARK_REGISTER_F(RingBufferMultiThreaded, MT)->Threads(16);
|
|
|
|
BENCHMARK_REGISTER_F(RingBufferMultiThreaded, MT)->Threads(64);
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
::benchmark::Initialize(&argc, argv);
|
|
|
|
::benchmark::RunSpecifiedBenchmarks();
|
|
|
|
return 0;
|
|
|
|
}
|