Add timing markers and output cuz why not

This commit is contained in:
Jose Caban
2025-12-02 01:44:17 -05:00
parent f9547469d9
commit 04595256fb

View File

@@ -1,13 +1,18 @@
#include "AdventHelpers/AdventOfCodeSolution.h"
#include <chrono>
#define ENABLE_EXCEPTION_HANDLING 0
namespace AdventHelpers
{
void AdventOfCodeSolution::SolveAll() {
auto timeStart = std::chrono::system_clock::now();
#if ENABLE_EXCEPTION_HANDLING
try {
#endif
auto timeLast = timeStart;
auto* exampleInput = GetExampleInputFile();
if (!exampleInput) {
std::cerr << "Failed to load example input file." << std::endl;
@@ -21,25 +26,31 @@ namespace AdventHelpers
return;
}
std::cout << "Loaded inputs files in: " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timeLast).count() << "ms" << std::endl;
// Problem 01, example input
std::cout << "Solving problem 01 using example input..." << std::endl;
timeLast = std::chrono::system_clock::now();
auto exampleResult01 = SolveProblem01(*exampleInput);
std::cout << "|- Got result: " << exampleResult01 << std::endl;
std::cout << "|- Got result: " << exampleResult01 << " in " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timeLast).count() << "ms" << std::endl;
// Problem 01, puzzle input
std::cout << "Solving problem 01 using puzzle input..." << std::endl;
timeLast = std::chrono::system_clock::now();
auto problemResult01 = SolveProblem01(*problemInput);
std::cout << "|- Got result: " << problemResult01 << std::endl;
std::cout << "|- Got result: " << problemResult01 << " in " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timeLast).count() << "ms" << std::endl;
// Problem 02, example input
std::cout << "Solving problem 02 using example input..." << std::endl;
timeLast = std::chrono::system_clock::now();
auto exampleResult02 = SolveProblem02(*exampleInput);
std::cout << "|- Got result: " << exampleResult02 << std::endl;
std::cout << "|- Got result: " << exampleResult02 << " in " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timeLast).count() << "ms" << std::endl;
// Problem 02, puzzle input
std::cout << "Solving problem 02 using puzzle input..." << std::endl;
timeLast = std::chrono::system_clock::now();
auto problemResult02 = SolveProblem02(*problemInput);
std::cout << "|- Got result: " << problemResult02 << std::endl;
std::cout << "|- Got result: " << problemResult02 << " in " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timeLast).count() << "ms" << std::endl;
AdventHelpers::InputFileHelper::destroy(exampleInput);
AdventHelpers::InputFileHelper::destroy(problemInput);
@@ -49,5 +60,6 @@ namespace AdventHelpers
std::cerr << "An unexpected error occurred while solving the problems." << std::endl;
}
#endif
std::cout << "Solved all problems in " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - timeLast).count() << "ms" << std::endl;
}
} // namespace AdventHelpers