Benchmark improvements
This commit is contained in:
parent
bd64157702
commit
2415fd02c2
1 changed files with 26 additions and 6 deletions
32
src/main.rs
32
src/main.rs
|
@ -121,13 +121,33 @@ async fn main() {
|
||||||
day.solve(part);
|
day.solve(part);
|
||||||
let end = Instant::now();
|
let end = Instant::now();
|
||||||
timings.push(end - start);
|
timings.push(end - start);
|
||||||
if i % (n / 100) == 0 {
|
|
||||||
print!("\r{}%", ((i as f32 / n as f32) * 100.0).round());
|
print!("\r{:.2}%", (i as f32 / n as f32) * 100.0);
|
||||||
let _ = std::io::stdout().flush();
|
let _ = std::io::stdout().flush();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let avg = timings.into_iter().sum::<Duration>() / n;
|
let avg = (timings.iter().sum::<Duration>() / n).as_nanos();
|
||||||
println!("\nAverage timing: {}µs", avg.as_nanos() as f64 / 1000.0);
|
let deviation = (avg - timings.iter().min().unwrap().as_nanos()).max(timings.iter().max().unwrap().as_nanos() - avg);
|
||||||
|
|
||||||
|
let (avg, avg_units) = if avg >= 1000000000 {
|
||||||
|
(avg as f64 / 1000000000.0, "s")
|
||||||
|
} else if avg >= 1000000 {
|
||||||
|
(avg as f64 / 1000000.0, "ms")
|
||||||
|
} else if avg >= 1000 {
|
||||||
|
(avg as f64 / 1000.0, "µs")
|
||||||
|
} else {
|
||||||
|
(avg as f64, "ns")
|
||||||
|
};
|
||||||
|
|
||||||
|
let (deviation, deviation_units) = if deviation >= 1000000000 {
|
||||||
|
(deviation as f64 / 1000000000.0, "s")
|
||||||
|
} else if deviation >= 1000000 {
|
||||||
|
(deviation as f64 / 1000000.0, "ms")
|
||||||
|
} else if deviation >= 1000 {
|
||||||
|
(deviation as f64 / 1000.0, "µs")
|
||||||
|
} else {
|
||||||
|
(deviation as f64, "ns")
|
||||||
|
};
|
||||||
|
println!("\nAverage timing: {avg}{avg_units} ± {deviation}{deviation_units}");
|
||||||
}
|
}
|
||||||
Subcommands::Input { day } => {
|
Subcommands::Input { day } => {
|
||||||
let response = client
|
let response = client
|
||||||
|
|
Loading…
Reference in a new issue