Use a common macro to instrument each part
This commit is contained in:
parent
200daf7336
commit
5fb0095dc6
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -8,9 +8,14 @@ version = "1.0.51"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
|
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "common"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "day01"
|
name = "day01"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"common",
|
||||||
]
|
]
|
||||||
|
8
crates/common/Cargo.toml
Normal file
8
crates/common/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "common"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
14
crates/common/src/lib.rs
Normal file
14
crates/common/src/lib.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! instrument {
|
||||||
|
($part1:expr, $part2:expr) => {
|
||||||
|
let mut now = Instant::now();
|
||||||
|
println!("Part 1: {}", $part1);
|
||||||
|
println!("(elapsed: {:?})", now.elapsed());
|
||||||
|
now = Instant::now();
|
||||||
|
println!("");
|
||||||
|
println!("Part 2: {}", $part2);
|
||||||
|
println!("(elapsed: {:?})", now.elapsed());
|
||||||
|
};
|
||||||
|
}
|
@ -7,3 +7,4 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
common = { path = "../common" }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use common::instrument;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
const INPUT: &str = include_str!("input/input.txt");
|
const INPUT: &str = include_str!("input/input.txt");
|
||||||
|
|
||||||
@ -41,13 +41,7 @@ fn solve_part2(input: &str) -> Result<i32> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut now = Instant::now();
|
instrument!(solve_part1(INPUT).unwrap(), solve_part2(INPUT).unwrap());
|
||||||
println!("Part 1: {}", solve_part1(INPUT).unwrap());
|
|
||||||
println!("(elapsed: {:?})", now.elapsed());
|
|
||||||
now = Instant::now();
|
|
||||||
println!("");
|
|
||||||
println!("Part 2: {}", solve_part2(INPUT).unwrap());
|
|
||||||
println!("(elapsed: {:?})", now.elapsed());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user