mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Add timing code.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "solutions.hpp"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
@@ -7,14 +8,16 @@ namespace po = boost::program_options;
|
||||
struct AoCOptions {
|
||||
int day;
|
||||
bool part2;
|
||||
bool run_timer;
|
||||
};
|
||||
|
||||
AoCOptions parse_options(const int argc, const char* argv[]) {
|
||||
static AoCOptions parse_options(const int argc, const char *argv[]) {
|
||||
AoCOptions options{};
|
||||
po::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("day", po::value<int>(&options.day)->required(), "The day to run.")
|
||||
("part2,2", po::bool_switch(&options.part2), "Whether to run part 2.");
|
||||
("part2,2", po::bool_switch(&options.part2), "Whether to run part 2.")
|
||||
("timer,t", po::bool_switch(&options.run_timer), "Show the execution time.");
|
||||
|
||||
po::positional_options_description positionals;
|
||||
positionals.add("day", 1);
|
||||
@@ -33,7 +36,12 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
const aoc2019::solution_t solution = aoc2019::get_implementation(options.day, options.part2);
|
||||
if (solution != nullptr) {
|
||||
const auto start = std::chrono::high_resolution_clock::now();
|
||||
solution(std::cin, std::cout);
|
||||
if (options.run_timer) {
|
||||
const std::chrono::duration<double> duration = std::chrono::high_resolution_clock::now() - start;
|
||||
std::cerr << "Time taken: " << duration.count() << "s\n";
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
std::cerr << "Unimplemented.\n";
|
||||
|
||||
Reference in New Issue
Block a user