Skip to content

Commit 1e9a91e

Browse files
committed
add timing helper method to shared library
1 parent c0390c7 commit 1e9a91e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

aoc/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ pub mod algs;
22
pub mod get_mut;
33
pub mod iterstuff;
44
pub mod stringstuff;
5+
mod time;
56
pub mod tree;
67
pub mod unionfind;
78

89
pub use aoc_macro::input_str;
910
pub use get_mut::GetMany;
1011
pub use iterstuff::IterJunk;
12+
pub use time::time;
1113
pub use tree::{Node, Tree};
1214
pub use unionfind::UnionFind;
1315

aoc/src/time.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub fn time<F, T>(task: &str, f: F) -> T
2+
where
3+
F: FnOnce() -> T,
4+
{
5+
let start = std::time::Instant::now();
6+
let result = f();
7+
println!("{}: {:?}", task, start.elapsed());
8+
result
9+
}

0 commit comments

Comments
 (0)