Skip to content

Commit 0c6338d

Browse files
committed
Reduce Option complexity in demo cpu_time
1 parent be99e50 commit 0c6338d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rayon-demo/src/cpu_time/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn get_cpu_time() -> Option<u64> {
1616
}
1717

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

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

0 commit comments

Comments
 (0)