Skip to content

Commit

Permalink
Time solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Dec 1, 2023
1 parent 008d225 commit 271bba4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions 2023/xmaslib/solution/solution.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
#include "solution.hpp"

#include <chrono>
#include <format>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>

#include <unistd.h>

namespace xmas {

void solution::run() {
std::cout << "Day 1" << std::endl;

try {
const auto p1 = this->part1();
std::cout << " Result 1: " << p1 << '\n';
const auto start = std::chrono::high_resolution_clock::now();
const auto result = this->part1();
const auto elapsed = std::chrono::high_resolution_clock::now() - start;

std::cout << std::format(" Result 1: {} ({} μs)\n", result, std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count());
} catch (std::runtime_error &err) {
std::cerr << "Part 1 failed with message: " << err.what() << std::endl;
}

try {
const auto p2 = this->part2();
std::cout << " Result 2: " << p2 << '\n';
const auto start = std::chrono::high_resolution_clock::now();
const auto result = this->part2();
const auto elapsed = std::chrono::high_resolution_clock::now() - start;

std::cout << std::format(" Result 2: {} ({} μs)\n", result, std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count());
} catch (std::runtime_error &err) {
std::cerr << "Part 2 failed with message: " << err.what() << std::endl;
}
Expand Down

0 comments on commit 271bba4

Please sign in to comment.