From a6cae3d5cfad59e16afa95926324bf8e93250019 Mon Sep 17 00:00:00 2001 From: Stein Somers Date: Sun, 2 Feb 2020 12:11:41 +0100 Subject: [PATCH] Add benchmarks of drain_filter-like behaviour --- src/liballoc/benches/btree/set.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/liballoc/benches/btree/set.rs b/src/liballoc/benches/btree/set.rs index d9e75ab7fa4..c4712e2132f 100644 --- a/src/liballoc/benches/btree/set.rs +++ b/src/liballoc/benches/btree/set.rs @@ -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::>() { + 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::>() { + 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);