Add basic benchmarking retroactively
This commit is contained in:
parent
d56bb85d9a
commit
ac04ea1ac2
4 changed files with 45 additions and 25 deletions
17
d1/main.cxx
17
d1/main.cxx
|
|
@ -10,7 +10,7 @@ constexpr const char content[] = {
|
|||
#embed "input.txt"
|
||||
};
|
||||
|
||||
void part_1() {
|
||||
int part_1() {
|
||||
std::vector<int> left_vec, right_vec;
|
||||
std::istringstream iss{content};
|
||||
|
||||
|
|
@ -27,10 +27,10 @@ void part_1() {
|
|||
diff_acc += std::abs(left_vec[i] - right_vec[i]);
|
||||
}
|
||||
|
||||
cout << diff_acc << endl;
|
||||
return diff_acc;
|
||||
}
|
||||
|
||||
void part_2() {
|
||||
int part_2() {
|
||||
std::vector<int> left_vec;
|
||||
std::unordered_map<int, int> right_map;
|
||||
std::istringstream iss{content};
|
||||
|
|
@ -46,11 +46,16 @@ void part_2() {
|
|||
sim_acc += right_map[left_num] * left_num;
|
||||
}
|
||||
|
||||
cout << sim_acc << endl;
|
||||
return sim_acc;
|
||||
}
|
||||
|
||||
int main() {
|
||||
part_1();
|
||||
part_2();
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
auto p1_val = part_1();
|
||||
std::chrono::steady_clock::time_point middle = std::chrono::steady_clock::now();
|
||||
auto p2_val = part_2();
|
||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||
cout << "Part 1: " << p1_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(middle - begin).count() << "µs)" << endl;
|
||||
cout << "Part 2: " << p2_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(end - middle).count() << "µs)" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
17
d2/main.cxx
17
d2/main.cxx
|
|
@ -40,7 +40,7 @@ bool safe(const std::vector<int>& level) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void part_1() {
|
||||
int part_1() {
|
||||
std::istringstream iss{content};
|
||||
std::string line;
|
||||
int correct_acc{0};
|
||||
|
|
@ -62,7 +62,7 @@ void part_1() {
|
|||
correct_acc++;
|
||||
}
|
||||
}
|
||||
cout << correct_acc << endl;
|
||||
return correct_acc;
|
||||
}
|
||||
|
||||
bool safe_dampener(const std::vector<int>& level) {
|
||||
|
|
@ -80,7 +80,7 @@ bool safe_dampener(const std::vector<int>& level) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void part_2() {
|
||||
int part_2() {
|
||||
std::istringstream iss{content};
|
||||
std::string line;
|
||||
int correct_acc{0};
|
||||
|
|
@ -102,11 +102,16 @@ void part_2() {
|
|||
correct_acc++;
|
||||
}
|
||||
}
|
||||
cout << correct_acc << endl;
|
||||
return correct_acc;
|
||||
}
|
||||
|
||||
int main() {
|
||||
part_1();
|
||||
part_2();
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
auto p1_val = part_1();
|
||||
std::chrono::steady_clock::time_point middle = std::chrono::steady_clock::now();
|
||||
auto p2_val = part_2();
|
||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||
cout << "Part 1: " << p1_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(middle - begin).count() << "µs)" << endl;
|
||||
cout << "Part 2: " << p2_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(end - middle).count() << "µs)" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
17
d3/main.cxx
17
d3/main.cxx
|
|
@ -7,7 +7,7 @@ constexpr const char content[] = {
|
|||
#embed "input.txt"
|
||||
};
|
||||
|
||||
void part_1() {
|
||||
int part_1() {
|
||||
std::string input = std::string(content);
|
||||
|
||||
auto acc{0};
|
||||
|
|
@ -22,10 +22,10 @@ void part_1() {
|
|||
input = match.suffix().str();
|
||||
}
|
||||
|
||||
cout << acc << endl;
|
||||
return acc;
|
||||
}
|
||||
|
||||
void part_2() {
|
||||
int part_2() {
|
||||
std::string input = std::string(content);
|
||||
|
||||
auto acc{0};
|
||||
|
|
@ -46,11 +46,16 @@ void part_2() {
|
|||
input = match.suffix().str();
|
||||
}
|
||||
|
||||
cout << acc << endl;
|
||||
return acc;
|
||||
}
|
||||
|
||||
int main() {
|
||||
part_1();
|
||||
part_2();
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
auto p1_val = part_1();
|
||||
std::chrono::steady_clock::time_point middle = std::chrono::steady_clock::now();
|
||||
auto p2_val = part_2();
|
||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||
cout << "Part 1: " << p1_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(middle - begin).count() << "µs)" << endl;
|
||||
cout << "Part 2: " << p2_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(end - middle).count() << "µs)" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
17
d4/main.cxx
17
d4/main.cxx
|
|
@ -48,7 +48,7 @@ int count_xmas(const std::vector<std::string> &grid, int i, int j) {
|
|||
return up + down + left + right + up_left + up_right + down_left + down_right;
|
||||
}
|
||||
|
||||
void part_1() {
|
||||
int part_1() {
|
||||
std::istringstream input_stream(content);
|
||||
std::string line;
|
||||
std::vector<std::string> grid;
|
||||
|
|
@ -66,7 +66,7 @@ void part_1() {
|
|||
}
|
||||
}
|
||||
|
||||
cout << count_acc << endl;
|
||||
return count_acc;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ bool is_mas_cross(const std::vector<std::string>& grid, int i, int j) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void part_2() {
|
||||
int part_2() {
|
||||
std::istringstream input_stream(content);
|
||||
std::string line;
|
||||
std::vector<std::string> grid;
|
||||
|
|
@ -112,11 +112,16 @@ void part_2() {
|
|||
}
|
||||
}
|
||||
|
||||
cout << count_acc << endl;
|
||||
return count_acc;
|
||||
}
|
||||
|
||||
int main() {
|
||||
part_1();
|
||||
part_2();
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
auto p1_val = part_1();
|
||||
std::chrono::steady_clock::time_point middle = std::chrono::steady_clock::now();
|
||||
auto p2_val = part_2();
|
||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||
cout << "Part 1: " << p1_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(middle - begin).count() << "µs)" << endl;
|
||||
cout << "Part 2: " << p2_val << " (" << std::chrono::duration_cast<std::chrono::microseconds>(end - middle).count() << "µs)" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue