-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory_bench.cpp
59 lines (48 loc) · 1.5 KB
/
history_bench.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
54
55
56
57
58
#include <unistd.h>
#include "history.hpp"
#include "counter.hpp"
#include "bench.hpp"
template<int N> struct history_bench : public benchmark {
struct element {
intptr_t v[N];
};
int thread_count;
int history_size;
history<element, raw_history> hist;
std::atomic<bool> start_;
std::atomic<bool> stop_;
typedef raw_history::version_t version_t;
history_bench(int t, int h) : thread_count(t), hist(h, t), history_size(h) { }
void thread(int thread_idx) {
element e;
while (should_continue()) {
version_t v = hist.get_version();
hist.publish(thread_idx, v+1, &e);
}
}
void execute(int seconds) {
std::cout << "History size: " << N << std::endl;
std::cout << "Thread count: " << thread_count << std::endl;
std::cout << "Benchmark duration [s]: " << seconds << std::endl;
run(seconds, thread_count);
int op_count = counter::get_counter(counter::History_PublishCall);
double duration = (1000.0 * 1000.0 * seconds * thread_count) / op_count;
std::cout << "Operation duration [us]: " << duration << std::endl;
std::cout << "Fraction of successful history updates: " << ((double)counter::get_counter(counter::History_PublishSucc)) / counter::get_counter(counter::History_PublishCall) << std::endl;
std::cout << std::endl;
}
};
int main(int argc, char **argv)
{
for(int i=1;i<argc;i++) {
int t = atoi(argv[i]);
if (t == 0)
continue;
history_bench<1> b1(t, 20);
b1.execute(20);
history_bench<2> b2(t, 20);
b2.execute(20);
history_bench<5> b5(t, 20);
b5.execute(20);
}
}