Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code shared from the Rust Playground
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
You can’t perform that action at this time.