Created
January 14, 2020 14:39
-
-
Save rust-play/3186ef3d443784bba4839f9da1e386f9 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::time::Instant; | |
fn main() { | |
let mut a: Vec<i32> = vec![1; 10000]; | |
let mut b: Vec<i32> = vec![1; 10000]; | |
let t = Instant::now(); | |
let mut nv = Vec::with_capacity(10000); | |
for i in a.iter() { | |
nv.push(*i * 2); | |
} | |
println!("{:?}", t.elapsed().as_nanos()); | |
let t1 = Instant::now(); | |
b.iter().map(|e| *e * 2).collect::<Vec<i32>>(); | |
println!("{:?}", t1.elapsed().as_nanos()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment