-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerf_expr_data_struct.hpp
More file actions
146 lines (115 loc) · 4.17 KB
/
Copy pathPerf_expr_data_struct.hpp
File metadata and controls
146 lines (115 loc) · 4.17 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef SERF_ALL_TEST_PERF_EXPR_DATA_STRUCT_HPP_
#define SERF_ALL_TEST_PERF_EXPR_DATA_STRUCT_HPP_
#include <iomanip>
#include <sstream>
#include <unordered_map>
#include <chrono>
static std::string double_to_string_with_precision(double val, size_t precision) {
std::ostringstream stringBuffer;
stringBuffer << std::fixed << std::setprecision(precision) << val;
return stringBuffer.str();
}
class ExprConf {
public:
struct hash {
std::size_t operator()(const ExprConf &conf) const {
std::string hash_str = conf.method_ + conf.data_set_ + conf.block_size_ + conf.float_len_;
if (!conf.beta_.empty()) {
hash_str += "_beta" + conf.beta_;
}
return std::hash<std::string>()(hash_str);
}
};
ExprConf() = delete;
ExprConf(std::string method, std::string data_set, int block_size, bool enable_32 = false)
: method_(method), data_set_(data_set), block_size_(std::to_string(block_size)), float_len_(enable_32 ? "32" : "64"),
beta_("") {}
ExprConf(std::string method, std::string data_set, int block_size, int beta)
: method_(method), data_set_(data_set), block_size_(std::to_string(block_size)), float_len_("64"),
beta_(std::to_string(beta)) {}
bool operator==(const ExprConf &otherConf) const {
bool basic_equal = method_ == otherConf.method_ && data_set_ == otherConf.data_set_ &&
block_size_ == otherConf.block_size_ && float_len_ == otherConf.float_len_;
if (beta_.empty() && otherConf.beta_.empty()) {
return basic_equal;
} else {
return basic_equal && beta_ == otherConf.beta_;
}
}
std::string method() const {
return method_;
}
std::string data_set() const {
return data_set_;
}
std::string block_size() const {
return block_size_;
}
std::string float_len() const {
return float_len_;
}
std::string beta() const {
return beta_;
}
private:
const std::string method_;
const std::string data_set_;
const std::string block_size_;
const std::string float_len_;
const std::string beta_;
};
class PerfRecord {
public:
PerfRecord() = default;
void IncreaseCompressionTime(std::chrono::nanoseconds &duration) {
compression_time_ += duration;
}
auto compression_time_in_microseconds() {
return std::chrono::duration_cast<std::chrono::microseconds>(compression_time_);
}
double AvgCompressionTimePerBlock() {
if (block_count_ <= 0) return 0.0;
auto total_microseconds = std::chrono::duration_cast<std::chrono::microseconds>(compression_time_);
return static_cast<double>(total_microseconds.count()) / block_count_;
}
void IncreaseDecompressionTime(std::chrono::nanoseconds &duration) {
decompression_time_ += duration;
}
auto decompression_time_in_microseconds() {
return std::chrono::duration_cast<std::chrono::microseconds>(decompression_time_);
}
double AvgDecompressionTimePerBlock() {
if (block_count_ <= 0) return 0.0;
auto total_microseconds = std::chrono::duration_cast<std::chrono::microseconds>(decompression_time_);
return static_cast<double>(total_microseconds.count()) / block_count_;
}
long compressed_size_in_bits() {
return compressed_size_in_bits_;
}
void AddCompressedSize(long size) {
compressed_size_in_bits_ += size;
}
void set_block_count(int blockCount_) {
block_count_ = blockCount_;
}
int block_count() {
return block_count_;
}
double CalCompressionRatio(ExprConf &expr_conf) {
if (block_count_ <= 0) {
return 0;
}
int64_t total_bits = static_cast<int64_t>(block_count_)
* static_cast<int64_t>(std::stoi(expr_conf.block_size()))
* static_cast<int64_t>(std::stoi(expr_conf.float_len()));
return static_cast<double>(compressed_size_in_bits_) / total_bits;
}
private:
// CHANGE TO USE NANOSECOND
std::chrono::nanoseconds compression_time_ = std::chrono::nanoseconds::zero();
std::chrono::nanoseconds decompression_time_ = std::chrono::nanoseconds::zero();
long compressed_size_in_bits_ = 0;
int block_count_ = 0;
};
using ExprTable = std::unordered_map<ExprConf, PerfRecord, ExprConf::hash>;
#endif //SERF_ALL_TEST_PERF_EXPR_DATA_STRUCT_HPP_