From 7b75cda2539755b684dfb74a93f87f8b09e3e3d6 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 21 May 2018 18:34:41 -0600 Subject: [PATCH] p --- Chapter09/performance_profiling2.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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); + } + }