From b2087ba800937e357a94ff7491cefae15e5198ef Mon Sep 17 00:00:00 2001 From: cos Date: Tue, 1 Dec 2020 22:36:49 +0100 Subject: Add code to measure time and memory consumption --- 2020/rust/Cargo.toml | 1 + 2020/rust/day01/Cargo.toml | 1 + 2020/rust/day01/src/main.rs | 36 +++++++++++++++++++++--------------- 3 files changed, 23 insertions(+), 15 deletions(-) (limited to '2020/rust') diff --git a/2020/rust/Cargo.toml b/2020/rust/Cargo.toml index 9674b94..ee71f9e 100644 --- a/2020/rust/Cargo.toml +++ b/2020/rust/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "aoc", "day01", # "day02", # "day03", diff --git a/2020/rust/day01/Cargo.toml b/2020/rust/day01/Cargo.toml index 674217d..4bf07f8 100644 --- a/2020/rust/day01/Cargo.toml +++ b/2020/rust/day01/Cargo.toml @@ -5,4 +5,5 @@ authors = ["cos "] edition = "2018" [dependencies] +aoc = { path = "../aoc" } anyhow = "1.0" diff --git a/2020/rust/day01/src/main.rs b/2020/rust/day01/src/main.rs index 38f25d2..fb661e6 100644 --- a/2020/rust/day01/src/main.rs +++ b/2020/rust/day01/src/main.rs @@ -43,6 +43,8 @@ fn part2(input: &[usize]) -> Option { } fn main() { + let ( do_part_1, do_part_2 ) = aoc::do_parts(); + let filename = match args().nth(1) { Some(f) => f, None => { @@ -50,22 +52,26 @@ fn main() { std::process::exit(1); }, }; - match read_input(filename) { + match read_input(filename) { Ok(input) => { - match part1(&input) { - Some(solution) => println!("Part1, product found to be: {}", solution), - None => { - eprintln!("Part1, no solution found"); - std::process::exit(1); - } - }; - match part2(&input) { - Some(solution) => println!("Part2, product found to be: {}", solution), - None => { - eprintln!("Part2, no solution found"); - std::process::exit(1); - } - }; + if do_part_1 { + match part1(&input) { + Some(solution) => println!("Part1, product found to be: {}", solution), + None => { + eprintln!("Part1, no solution found"); + std::process::exit(1); + } + }; + } + if do_part_2 { + match part2(&input) { + Some(solution) => println!("Part2, product found to be: {}", solution), + None => { + eprintln!("Part2, no solution found"); + std::process::exit(1); + } + }; + } }, Err(err) => eprintln!("Could not read input: {}", err), } -- cgit v1.2.3