Add benchmarks of drain_filter-like behaviour

This commit is contained in:
Stein Somers 2020-02-02 12:11:41 +01:00
parent 8ab82b87af
commit a6cae3d5cf

View File

@ -62,6 +62,18 @@ pub fn clone_100_and_clear(b: &mut Bencher) {
b.iter(|| src.clone().clear())
}
#[bench]
pub fn clone_100_and_drain_half(b: &mut Bencher) {
let src = pos(100);
b.iter(|| {
let mut set = src.clone();
for i in set.iter().copied().filter(|i| i % 2 == 0).collect::<Vec<_>>() {
set.remove(&i);
}
assert_eq!(set.len(), 100 / 2);
})
}
#[bench]
pub fn clone_100_and_into_iter(b: &mut Bencher) {
let src = pos(100);
@ -115,6 +127,18 @@ pub fn clone_10k_and_clear(b: &mut Bencher) {
b.iter(|| src.clone().clear())
}
#[bench]
pub fn clone_10k_and_drain_half(b: &mut Bencher) {
let src = pos(10_000);
b.iter(|| {
let mut set = src.clone();
for i in set.iter().copied().filter(|i| i % 2 == 0).collect::<Vec<_>>() {
set.remove(&i);
}
assert_eq!(set.len(), 10_000 / 2);
})
}
#[bench]
pub fn clone_10k_and_into_iter(b: &mut Bencher) {
let src = pos(10_000);