-
Notifications
You must be signed in to change notification settings - Fork 1
/
FastForwardTest.cpp
53 lines (48 loc) · 1.63 KB
/
FastForwardTest.cpp
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
49
50
51
52
53
#include "FastForward1.hpp"
#include "FastForward2.hpp"
#include "FastForward3.hpp"
#include "FastForward4.hpp"
#include "FastForward5.hpp"
#include "FastForward6.hpp"
#include "BenchmarkSupport.hpp"
#include "Platform.hpp"
#include <new>
template<typename type>
static void FastForwardTest(benchmark::State& state) {
static std::atomic<type*> queue = nullptr;
if (state.thread_index() == 0) {
queue.store(new type);
} else {
while (queue.load() == nullptr) {}
}
static typename type::value_type value{};
type& q = *queue;
if (state.thread_index() == 0) {
PREPARE_THREAD(Thread1Affinity);
for (auto _ : state) {
int counter = 10000;
while (counter > 0) {
counter -= int(q.Enqueue(&value));
}
}
} else if (state.thread_index() == 1) {
PREPARE_THREAD(Thread2Affinity);
typename type::value_type* out;
for (auto _ : state) {
int counter = 10000;
while (counter > 0) {
counter -= int(q.Dequeue(out));
}
}
delete queue.load();
queue.store(nullptr);
}
state.SetItemsProcessed(state.iterations() * 10000);
state.SetBytesProcessed(state.iterations() * 10000 * sizeof(typename type::value_type));
}
QUEUE_BENCH_FOR_SIZE(FastForwardTest, FastForward1, 8);
QUEUE_BENCH_FOR_SIZE(FastForwardTest, FastForward2, 8);
QUEUE_BENCH_FOR_SIZE(FastForwardTest, FastForward3, 8);
QUEUE_BENCH_FOR_SIZE(FastForwardTest, FastForward4, 8);
QUEUE_BENCH_FOR_SIZE(FastForwardTest, FastForward5, 8);
QUEUE_BENCH_FOR_SIZE(FastForwardTest, FastForward6, 8);