From f426e7067abff1133a0841944b2f677e3f25b4c4 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Wed, 5 Dec 2018 12:23:54 +0100 Subject: [PATCH] More easily time the program. --- 2018/src/main.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/2018/src/main.rs b/2018/src/main.rs index bf5b6ce..3a9fb55 100644 --- a/2018/src/main.rs +++ b/2018/src/main.rs @@ -1,10 +1,13 @@ -extern crate clap; extern crate chrono; -extern crate regex; +extern crate clap; #[macro_use] extern crate itertools; -use clap::{Arg, App}; +extern crate regex; + use std::fs; use std::io; +use std::time::Instant; + +use clap::{App, Arg}; pub mod common; pub mod day01; @@ -43,6 +46,10 @@ fn main() { .long("input") .help("Optional input file, stdin otherwise") .takes_value(true)) + .arg(Arg::with_name("time") + .short("t") + .long("time") + .help("Print the time for the result")) .get_matches(); let mut implementation = get_impl(matches.value_of("day").unwrap()); @@ -51,11 +58,16 @@ fn main() { None => { Box::new(io::stdin()) } }; - if matches.is_present("part2") { - println!("{}", implementation.part2(&mut data)); + let begin = Instant::now(); + let result = if matches.is_present("part2") { + implementation.part2(&mut data) } else { - println!("{}", implementation.part1(&mut data)); + implementation.part1(&mut data) + }; + if matches.is_present("time") { + eprintln!("Duration: {:?}", Instant::now().duration_since(begin)); } + println!("{}", result); } #[cfg(test)]