mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 13:50:32 +01:00
More easily time the program.
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
extern crate clap;
|
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate regex;
|
extern crate clap;
|
||||||
#[macro_use] extern crate itertools;
|
#[macro_use] extern crate itertools;
|
||||||
use clap::{Arg, App};
|
extern crate regex;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod day01;
|
pub mod day01;
|
||||||
@@ -43,6 +46,10 @@ fn main() {
|
|||||||
.long("input")
|
.long("input")
|
||||||
.help("Optional input file, stdin otherwise")
|
.help("Optional input file, stdin otherwise")
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
|
.arg(Arg::with_name("time")
|
||||||
|
.short("t")
|
||||||
|
.long("time")
|
||||||
|
.help("Print the time for the result"))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let mut implementation = get_impl(matches.value_of("day").unwrap());
|
let mut implementation = get_impl(matches.value_of("day").unwrap());
|
||||||
@@ -51,11 +58,16 @@ fn main() {
|
|||||||
None => { Box::new(io::stdin()) }
|
None => { Box::new(io::stdin()) }
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.is_present("part2") {
|
let begin = Instant::now();
|
||||||
println!("{}", implementation.part2(&mut data));
|
let result = if matches.is_present("part2") {
|
||||||
|
implementation.part2(&mut data)
|
||||||
} else {
|
} 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)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user