Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcrichton/03d666159a28a80e7c70 to your computer and use it in GitHub Desktop.
Save alexcrichton/03d666159a28a80e7c70 to your computer and use it in GitHub Desktop.
#![feature(collections, test)]
extern crate test;
const AMT1: usize = 1000;
const AMT2: usize = 1001;
const E1: u8 = 0;
const E2: u8 = 2;
#[bench]
fn macro_repeat1(b: &mut test::Bencher) {
b.iter(|| { vec![E1; AMT1] });
}
#[bench]
fn macro_repeat2(b: &mut test::Bencher) {
b.iter(|| { vec![E2; AMT2] });
}
#[bench]
fn map_clone1(b: &mut test::Bencher) {
b.iter(|| {
(0..AMT1).map(|_| E1).collect::<Vec<_>>()
});
}
#[bench]
fn map_clone2(b: &mut test::Bencher) {
b.iter(|| {
(0..AMT2).map(|_| E2).collect::<Vec<_>>()
});
}
#[bench]
fn repeat1(b: &mut test::Bencher) {
b.iter(|| {
std::iter::repeat(E1).take(AMT1).collect::<Vec<_>>()
});
}
#[bench]
fn repeat2(b: &mut test::Bencher) {
b.iter(|| {
std::iter::repeat(E2).take(AMT2).collect::<Vec<_>>()
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment