Skip to content

Commit

Permalink
Add a separate Stopwatch status for when no job durations have been m…
Browse files Browse the repository at this point in the history
…easured
  • Loading branch information
ndebuhr committed Jul 5, 2021
1 parent 2a70d21 commit f4a1728
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions sim/src/models/stopwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,21 @@ impl Stopwatch {

impl AsModel for Stopwatch {
fn status(&self) -> String {
let durations: Vec<f64> = self
.state
.jobs
.iter()
.filter_map(|job| self.some_duration(job))
.map(|(_, duration)| duration)
.collect();
format![
"Average {:.3}",
durations.iter().sum::<f64>() / durations.len() as f64
]
if self.state.jobs.is_empty() {
String::from("Measuring durations")
} else {
let durations: Vec<f64> = self
.state
.jobs
.iter()
.filter_map(|job| self.some_duration(job))
.map(|(_, duration)| duration)
.collect();
format![
"Average {:.3}",
durations.iter().sum::<f64>() / durations.len() as f64
]
}
}

fn events_ext(
Expand Down

0 comments on commit f4a1728

Please sign in to comment.