Skip to content

Commit

Permalink
Reduce Option complexity in demo cpu_time
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Nov 20, 2019
1 parent be99e50 commit 0c6338d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rayon-demo/src/cpu_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn get_cpu_time() -> Option<u64> {
}

pub fn get_cpu_duration(start: Option<u64>, stop: Option<u64>) -> Option<Duration> {
start.and_then(|start| stop.and_then(|stop| Some(Duration::nanoseconds((stop - start) as i64))))
Some(Duration::nanoseconds((stop? - start?) as i64))
}

#[derive(Copy, Clone)]
Expand All @@ -41,7 +41,7 @@ pub fn measure_cpu(op: impl FnOnce()) -> CpuMeasure {
time_duration,
cpu_usage_percent: get_cpu_duration(cpu_start, cpu_stop)
.and_then(|cpu| cpu.num_nanoseconds())
.and_then(|cpu| Some(100.0 * cpu as f64 / time_duration as f64)),
.map(|cpu| 100.0 * cpu as f64 / time_duration as f64),
}
}

Expand Down

0 comments on commit 0c6338d

Please sign in to comment.