Created
March 14, 2019 19:49
-
-
Save rust-play/c8fcb2cb741f28b84ba8c1a3876ed5e1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or 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
#![feature(test)] | |
mod bench { | |
extern crate test; | |
#[bench] | |
fn chain(b: &mut Bencher) { | |
b.iter(|| { | |
let a = (0..500000).map(|x| x * 2); | |
let b = (0..500000).map(|x| x * 3); | |
let _c: Vec<_> = a.chain(b).collect(); | |
}) | |
} | |
#[bench] | |
fn extend(b: &mut Bencher) { | |
b.iter(|| { | |
let a = (0..500000).map(|x| x * 2); | |
let b = (0..500000).map(|x| x * 3); | |
let mut c = Vec::with_capacity(a.size_hint().1.unwrap() + b.size_hint().1.unwrap()); | |
c.extend(a); | |
c.extend(b); | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment