diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /library/std/benches | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/std/benches')
-rw-r--r-- | library/std/benches/hash/map.rs | 103 | ||||
-rw-r--r-- | library/std/benches/hash/mod.rs | 2 | ||||
-rw-r--r-- | library/std/benches/hash/set_ops.rs | 42 | ||||
-rw-r--r-- | library/std/benches/lib.rs | 5 |
4 files changed, 152 insertions, 0 deletions
diff --git a/library/std/benches/hash/map.rs b/library/std/benches/hash/map.rs new file mode 100644 index 000000000..bf646cbae --- /dev/null +++ b/library/std/benches/hash/map.rs @@ -0,0 +1,103 @@ +#![cfg(test)] + +use std::collections::HashMap; +use test::Bencher; + +#[bench] +fn new_drop(b: &mut Bencher) { + b.iter(|| { + let m: HashMap<i32, i32> = HashMap::new(); + assert_eq!(m.len(), 0); + }) +} + +#[bench] +fn new_insert_drop(b: &mut Bencher) { + b.iter(|| { + let mut m = HashMap::new(); + m.insert(0, 0); + assert_eq!(m.len(), 1); + }) +} + +#[bench] +fn grow_by_insertion(b: &mut Bencher) { + let mut m = HashMap::new(); + + for i in 1..1001 { + m.insert(i, i); + } + + let mut k = 1001; + + b.iter(|| { + m.insert(k, k); + k += 1; + }); +} + +#[bench] +fn find_existing(b: &mut Bencher) { + let mut m = HashMap::new(); + + for i in 1..1001 { + m.insert(i, i); + } + + b.iter(|| { + for i in 1..1001 { + m.contains_key(&i); + } + }); +} + +#[bench] +fn find_nonexisting(b: &mut Bencher) { + let mut m = HashMap::new(); + + for i in 1..1001 { + m.insert(i, i); + } + + b.iter(|| { + for i in 1001..2001 { + m.contains_key(&i); + } + }); +} + +#[bench] +fn hashmap_as_queue(b: &mut Bencher) { + let mut m = HashMap::new(); + + for i in 1..1001 { + m.insert(i, i); + } + + let mut k = 1; + + b.iter(|| { + m.remove(&k); + m.insert(k + 1000, k + 1000); + k += 1; + }); +} + +#[bench] +fn get_remove_insert(b: &mut Bencher) { + let mut m = HashMap::new(); + + for i in 1..1001 { + m.insert(i, i); + } + + let mut k = 1; + + b.iter(|| { + m.get(&(k + 400)); + m.get(&(k + 2000)); + m.remove(&k); + m.insert(k + 1000, k + 1000); + k += 1; + }) +} diff --git a/library/std/benches/hash/mod.rs b/library/std/benches/hash/mod.rs new file mode 100644 index 000000000..42401a21b --- /dev/null +++ b/library/std/benches/hash/mod.rs @@ -0,0 +1,2 @@ +mod map; +mod set_ops; diff --git a/library/std/benches/hash/set_ops.rs b/library/std/benches/hash/set_ops.rs new file mode 100644 index 000000000..1a4c4a66e --- /dev/null +++ b/library/std/benches/hash/set_ops.rs @@ -0,0 +1,42 @@ +use std::collections::HashSet; +use test::Bencher; + +#[bench] +fn set_difference(b: &mut Bencher) { + let small: HashSet<_> = (0..10).collect(); + let large: HashSet<_> = (0..100).collect(); + + b.iter(|| small.difference(&large).count()); +} + +#[bench] +fn set_is_subset(b: &mut Bencher) { + let small: HashSet<_> = (0..10).collect(); + let large: HashSet<_> = (0..100).collect(); + + b.iter(|| small.is_subset(&large)); +} + +#[bench] +fn set_intersection(b: &mut Bencher) { + let small: HashSet<_> = (0..10).collect(); + let large: HashSet<_> = (0..100).collect(); + + b.iter(|| small.intersection(&large).count()); +} + +#[bench] +fn set_symmetric_difference(b: &mut Bencher) { + let small: HashSet<_> = (0..10).collect(); + let large: HashSet<_> = (0..100).collect(); + + b.iter(|| small.symmetric_difference(&large).count()); +} + +#[bench] +fn set_union(b: &mut Bencher) { + let small: HashSet<_> = (0..10).collect(); + let large: HashSet<_> = (0..100).collect(); + + b.iter(|| small.union(&large).count()); +} diff --git a/library/std/benches/lib.rs b/library/std/benches/lib.rs new file mode 100644 index 000000000..4d1cf7fab --- /dev/null +++ b/library/std/benches/lib.rs @@ -0,0 +1,5 @@ +#![feature(test)] + +extern crate test; + +mod hash; |