-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsum_bench.cpp
66 lines (56 loc) · 2.06 KB
/
parsum_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
59
60
61
62
63
64
65
66
#include "parsum.hpp"
#include "counter.hpp"
#include "bench.hpp"
#include <unistd.h>
#include <iostream>
struct intpair {
intptr_t first, second;
intpair() = default;
intpair(int f, int s) {
first = f;
second = s;
}
};
intpair operator+(const intpair& a, const intpair& b) {
return intpair(a.first + b.first, a.second + b.second);
}
// Snapshot should be a snapshot on intpair
struct reducing_snapshot_bench : public benchmark {
typedef reducing_snapshot<intptr_t> Snapshot;
int thread_count;
std::unique_ptr<Snapshot> summer;
void thread(int thread_idx) {
intptr_t i = 1;
while (should_continue()) {
summer->update(thread_idx, &i);
i++;
counter::inc_counter(counter::Parsum_Ops, 1);
}
}
void execute(int seconds) {
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::Parsum_Ops);
double duration = (1000.0 * 1000.0 * seconds * thread_count) / op_count;
std::cout << "Operation duration [us]: " << duration << std::endl;
std::cout << "Updates with own publish: " << ((double)counter::get_counter(counter::Parsum_OwnPublish)) / counter::get_counter(counter::Parsum_Update) << std::endl;
std::cout << "Full update_lasts: " << ((double)counter::get_counter(counter::Parsum_UpdateLastExec)) / counter::get_counter(counter::Parsum_UpdateLastCall) << std::endl;
std::cout << "Full update_lasts per update: " << ((double)counter::get_counter(counter::Parsum_UpdateLastExec)) / counter::get_counter(counter::Parsum_Update) << 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;
}
reducing_snapshot_bench(int t) :
thread_count(t),
summer(Snapshot::create(t))
{ }
};
int main(int argc, char **argv)
{
for(int i=1;i<argc;i++) {
int t = atoi(argv[i]);
if (t == 0) continue;
reducing_snapshot_bench b(t);
b.execute(20);
}
}