-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
127 lines (100 loc) · 4.09 KB
/
main.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
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
#include <algorithm>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
namespace {
std::map<std::string, std::vector<double>> header_time_map;
void GetElapsedTime(const std::filesystem::path& json_file) {
auto filename = std::filesystem::path(json_file).filename().string();
auto boost_ending = filename.find("-hpp_main.cpp.json");
if (boost_ending == std::string::npos)
filename.resize(filename.find("_main.cpp.json"));
else {
filename.resize(boost_ending);
std::replace(filename.begin(), filename.end(), '-', '/');
filename += ".hpp";
}
std::ifstream json_stream(json_file);
auto str = std::string((std::istreambuf_iterator<char>(json_stream)), std::istreambuf_iterator<char>());
auto offset = str.find("avg ms");
str = str.substr(offset + 8);
str.resize(str.find('}'));
auto elapsed = std::atof(str.c_str());
header_time_map[filename].push_back(elapsed);
}
template <typename T>
void PrintTop5(const std::string& name, T& vector, double baseline, std::ostream& table) {
std::partial_sort(vector.begin(), vector.begin() + std::min(static_cast<int>(vector.size()), 5), vector.end(), [](auto&lhs, auto&rhs) {
return lhs.second > rhs.second;
});
table << "# Top-5 " << name << " headers compilation impact" << std::endl;
table << "| Header | Time, ms | Relative slowdown |" << std::endl;
table << "|- |- |- |" << std::endl;
for (std::size_t i = 0; i < std::min(static_cast<int>(vector.size()), 5); ++i)
table << "|" << vector[i].first << "\t|" << vector[i].second << "\t|" << vector[i].second / baseline << "\t|" << std::endl;
table << std::endl << std::endl << std::endl;
}
template <typename T>
void PrintTable(const std::string& name, T& vector, double baseline, std::ostream& table) {
std::sort(vector.begin(), vector.end(), [](auto&lhs, auto&rhs) {
return lhs.first < rhs.first;
});
table << "# " << name << " headers compilation impact" << std::endl;
table << "| Header | Time, ms | Relative slowdown |" << std::endl;
table << "|- |- |- |" << std::endl;
for (auto& el : vector)
table << "|" << el.first << "\t|" << el.second << "\t|" << el.second / baseline << "\t|" << std::endl;
table << std::endl << std::endl << std::endl;
}
}
int main(int argc, char** argv) {
try {
auto files_path = std::filesystem::absolute(std::filesystem::path(argv[0]).remove_filename());
for (auto build : std::filesystem::directory_iterator(files_path)) {
auto build_path = std::filesystem::path(build) / "CMakeFiles";
if (!std::filesystem::exists(build_path))
continue;
for (auto& el : std::filesystem::directory_iterator(build_path)) {
if (!std::filesystem::is_directory(el))
continue;
if (std::filesystem::path(el).string().find(".dir") == std::string::npos)
continue;
for (auto& el_file : std::filesystem::directory_iterator(el)) {
if (std::filesystem::path(el_file).extension().string() == ".json") {
GetElapsedTime(el_file);
}
}
}
}
auto markdown_table = std::ofstream("check_compile_times.wiki/Home.md");
std::ostream* table_ptr = &std::cout;
if (markdown_table.is_open())
table_ptr = &markdown_table;
std::vector<std::pair<std::string, double>> sorted_times_stl;
std::vector<std::pair<std::string, double>> sorted_times_boost;
double baseline = -1;
for (auto& el : header_time_map) {
auto time = std::accumulate(el.second.begin(), el.second.end(), 0.0);
time /= el.second.size();
if (el.first.find("baseline") != std::string::npos)
baseline = time;
if (el.first.find("boost") != std::string::npos)
sorted_times_boost.emplace_back(el.first, time);
else
sorted_times_stl.emplace_back(el.first, time);
}
PrintTop5("STL", sorted_times_stl, baseline, *table_ptr);
PrintTop5("Boost", sorted_times_boost, baseline, *table_ptr);
PrintTable("STL", sorted_times_stl, baseline, *table_ptr);
PrintTable("Boost", sorted_times_boost, baseline, *table_ptr);
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}