Last active
October 27, 2016 17:29
-
-
Save bluss/fad6a046491896ae4a4bf4655869b869 to your computer and use it in GitHub Desktop.
(Note: I also tested instead of chaining on single elements, chaining the slice half and half, and qualitatively it has the same result)
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
Improvements with impl TrustedLen on Chain, and using TrustedLen in Vec::extend | |
name extend-before-1.log ns/iter extend-after-1.log ns/iter diff ns/iter diff % | |
bench_chain_chain_collect 62,249 32,370 -29,879 -48.00% | |
bench_chain_collect 26,828 25,386 -1,442 -5.37% | |
bench_nest_chain_chain_collect 44,562 41,087 -3,475 -7.80% | |
/Additional/ improvements using `.fold()` too in Vec::extend | |
name extend-after-1.log ns/iter extend-after-fold-2.log ns/iter diff ns/iter diff % | |
bench_chain_chain_collect 32,370 2,762 -29,608 -91.47% | |
bench_chain_collect 25,386 2,760 -22,626 -89.13% | |
bench_nest_chain_chain_collect 41,087 2,744 -38,343 -93.32% |
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
#[bench] | |
fn bench_chain_collect(b: &mut test::Bencher) { | |
let data = black_box([0; LEN]); | |
b.iter(|| { | |
data.iter().cloned().chain([1].iter().cloned()).collect::<Vec<_>>() | |
}); | |
} | |
#[bench] | |
fn bench_chain_chain_collect(b: &mut test::Bencher) { | |
let data = black_box([0; LEN]); | |
b.iter(|| { | |
data.iter().cloned().chain([1].iter().cloned()).chain([2].iter().cloned()).collect::<Vec<_>>() | |
}); | |
} | |
#[bench] | |
fn bench_nest_chain_chain_collect(b: &mut test::Bencher) { | |
let data = black_box([0; LEN]); | |
b.iter(|| { | |
data.iter().cloned().chain([1].iter().chain([2].iter()).cloned()).collect::<Vec<_>>() | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment