Skip to content

Commit ad781cf

Browse files
committed
Use Duration for timing
1 parent ae57ea1 commit ad781cf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::env::args;
55
use std::fs::read_to_string;
66
use std::iter::empty;
77
use std::path::PathBuf;
8+
use std::time::Duration;
89
use std::time::Instant;
910

1011
fn main() {
@@ -33,7 +34,7 @@ fn main() {
3334
.collect();
3435

3536
// Pretty print output and timing for each solution
36-
let mut elapsed = 0;
37+
let mut elapsed = Duration::ZERO;
3738

3839
for Solution { year, day, wrapper } in &solutions {
3940
let path: PathBuf =
@@ -46,7 +47,7 @@ fn main() {
4647
let time = Instant::now();
4748
let (answer1, answer2) = wrapper(&data);
4849
let duration = time.elapsed().as_micros();
49-
elapsed += duration;
50+
elapsed += time.elapsed();
5051

5152
println!("{BOLD}{YELLOW}{year} Day {day:02}{RESET}");
5253
println!(" Part 1: {answer1}");
@@ -56,7 +57,7 @@ fn main() {
5657

5758
// Print totals
5859
println!("{BOLD}{RED}Solutions: {}{RESET}", solutions.len());
59-
println!("{BOLD}{GREEN}Elapsed: {} ms{RESET}", elapsed / 1000);
60+
println!("{BOLD}{GREEN}Elapsed: {} ms{RESET}", elapsed.as_millis());
6061
}
6162

6263
struct Solution {

0 commit comments

Comments
 (0)