Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 14, 2019 19:49
Show Gist options
  • Save rust-play/c8fcb2cb741f28b84ba8c1a3876ed5e1 to your computer and use it in GitHub Desktop.
Save rust-play/c8fcb2cb741f28b84ba8c1a3876ed5e1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![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