-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiubench.h
More file actions
80 lines (67 loc) · 1.94 KB
/
Copy pathiubench.h
File metadata and controls
80 lines (67 loc) · 1.94 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _IUBENCH_H_
#define _IUBENCH_H_
#include <chrono>
#include <stdint.h>
#define _1K() (1000LL)
#define _1M() (_1K() * 1000LL)
#define _1G() (_1M() * 1000LL)
class IUbench {
public:
virtual double CalNsPerInstruction() {
return (double)ns_ / (instruction_count_ * iter_);
}
virtual double CalInstructionPerNs() {
return ((double)instruction_count_ * iter_) / ns_;
}
virtual double CalOpsPerNs() {
return ((double)ops_count_ * iter_) / ns_;
}
virtual void Bench(const int64_t warm_up, const int64_t iter) {
warm_up_ = warm_up;
iter_ = iter;
int64_t l = warm_up;
while (l--) {
BenchImpl();
}
l = iter;
auto t0 = std::chrono::high_resolution_clock::now();
while (l--) {
BenchImpl();
}
auto t1 = std::chrono::high_resolution_clock::now();
ns_ = (t1 - t0).count();
}
virtual int64_t BenchLimitTime(const int64_t warm_up, const int64_t iter, const double ms) {
warm_up_ = warm_up;
iter_ = iter;
int64_t l = warm_up;
while (l--) {
BenchImpl();
}
l = 0;
ns_ = 0;
while (l < iter || ns_ < ms * 1e6) {
auto t0 = std::chrono::high_resolution_clock::now();
BenchImpl();
auto t1 = std::chrono::high_resolution_clock::now();
l++;
ns_ += (t1 - t0).count();
}
return l;
}
int64_t GetWarmUp() { return warm_up_; }
int64_t GetIter() { return iter_; }
int64_t GetNs() { return ns_; }
int64_t GetInstructionCount() { return instruction_count_; }
int64_t GetOpsCount() { return ops_count_; }
int64_t GetBytesCount() { return bytes_count_; }
protected:
int64_t warm_up_;
int64_t iter_;
int64_t ns_ = 0;
int64_t instruction_count_;
int64_t ops_count_;
int64_t bytes_count_;
virtual void BenchImpl() = 0;
};
#endif