diff --git a/Chapter09/performance_profiling2.rs b/Chapter09/performance_profiling2.rs index f79c691..b0ca79e 100644 --- a/Chapter09/performance_profiling2.rs +++ b/Chapter09/performance_profiling2.rs @@ -1,2 +1,24 @@ +use std::{thread,time}; + +fn initialization() -> Vec { + let t = time::Duration::from_millis(15000); + thread::sleep(t); + println!("Initialize data."); + vec![1, 2, 3] +} + +fn work(x: i32) -> i32 { + let t = time::Duration::from_millis(150); + thread::sleep(t); + println!("Work."); + x * x +} + fn main() { + + for _ in 0..10 { + let data = initialization(); + data.iter().map(|x| work(*x)).for_each(drop); + } + }