mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Add benchmarks of drain_filter-like behaviour
This commit is contained in:
parent
8ab82b87af
commit
a6cae3d5cf
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user