From c797e874d5760b54024ddd1c13214bc06ac0ae5e Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Tue, 12 Dec 2023 02:24:24 -0800 Subject: [PATCH] boilerplate: add timing --- boilerplate/src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/boilerplate/src/main.rs b/boilerplate/src/main.rs index 07318aa..0e47f70 100644 --- a/boilerplate/src/main.rs +++ b/boilerplate/src/main.rs @@ -1,5 +1,6 @@ use std::fs::File; use std::io::{BufRead, BufReader, Lines}; +use std::time::{Duration, Instant}; // BOILERPLATE type InputIter = Lines>; @@ -11,8 +12,15 @@ fn get_input() -> InputIter { } fn main() { - println!("Problem 1 solution: {}", problem1(get_input())); - println!("Problem 2 solution: {}", problem2(get_input())); + let start = Instant::now(); + let ans1 = problem1(get_input()); + let duration = start.elapsed(); + println!("Problem 1 solution: {} [{}s]", ans1, duration.as_secs_f64()); + + let start = Instant::now(); + let ans2 = problem2(get_input()); + let duration = start.elapsed(); + println!("Problem 2 solution: {} [{}s]", ans2, duration.as_secs_f64()); } // PROBLEM 1 solution