summaryrefslogtreecommitdiffstats
path: root/vendor/ahash/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /vendor/ahash/tests
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ahash/tests')
-rw-r--r--vendor/ahash/tests/bench.rs139
-rw-r--r--vendor/ahash/tests/map_tests.rs39
-rw-r--r--vendor/ahash/tests/nopanic.rs35
3 files changed, 186 insertions, 27 deletions
diff --git a/vendor/ahash/tests/bench.rs b/vendor/ahash/tests/bench.rs
index 9e6dccc48..84a373959 100644
--- a/vendor/ahash/tests/bench.rs
+++ b/vendor/ahash/tests/bench.rs
@@ -1,20 +1,32 @@
-use ahash::{CallHasher, RandomState};
+#![cfg_attr(feature = "specialize", feature(build_hasher_simple_hash_one))]
+
+use ahash::{AHasher, RandomState};
use criterion::*;
use fxhash::FxHasher;
use std::collections::hash_map::DefaultHasher;
-use std::hash::{Hash, Hasher};
+use std::hash::{BuildHasherDefault, Hash, Hasher};
#[cfg(any(
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
+ all(
+ any(target_arch = "arm", target_arch = "aarch64"),
+ any(target_feature = "aes", target_feature = "crypto"),
+ not(miri),
+ feature = "stdsimd"
+ )
))]
fn aeshash<H: Hash>(b: &H) -> u64 {
let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
- H::get_hash(b, &build_hasher)
+ build_hasher.hash_one(b)
}
#[cfg(not(any(
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
+ all(
+ any(target_arch = "arm", target_arch = "aarch64"),
+ any(target_feature = "aes", target_feature = "crypto"),
+ not(miri),
+ feature = "stdsimd"
+ )
)))]
fn aeshash<H: Hash>(_b: &H) -> u64 {
panic!("aes must be enabled")
@@ -22,15 +34,25 @@ fn aeshash<H: Hash>(_b: &H) -> u64 {
#[cfg(not(any(
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
+ all(
+ any(target_arch = "arm", target_arch = "aarch64"),
+ any(target_feature = "aes", target_feature = "crypto"),
+ not(miri),
+ feature = "stdsimd"
+ )
)))]
fn fallbackhash<H: Hash>(b: &H) -> u64 {
let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
- H::get_hash(b, &build_hasher)
+ build_hasher.hash_one(b)
}
#[cfg(any(
all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
- all(any(target_arch = "arm", target_arch = "aarch64"), target_feature = "crypto", not(miri), feature = "stdsimd")
+ all(
+ any(target_arch = "arm", target_arch = "aarch64"),
+ any(target_feature = "aes", target_feature = "crypto"),
+ not(miri),
+ feature = "stdsimd"
+ )
))]
fn fallbackhash<H: Hash>(_b: &H) -> u64 {
panic!("aes must be disabled")
@@ -82,6 +104,7 @@ const U32_VALUE: u32 = 12345678;
const U64_VALUE: u64 = 1234567890123456;
const U128_VALUE: u128 = 12345678901234567890123456789012;
+#[cfg(target_feature = "aes")]
fn bench_ahash(c: &mut Criterion) {
let mut group = c.benchmark_group("aeshash");
group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(aeshash(s))));
@@ -92,6 +115,7 @@ fn bench_ahash(c: &mut Criterion) {
group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(aeshash(s))));
}
+#[cfg(not(target_feature = "aes"))]
fn bench_fallback(c: &mut Criterion) {
let mut group = c.benchmark_group("fallback");
group.bench_with_input("u8", &U8_VALUE, |b, s| b.iter(|| black_box(fallbackhash(s))));
@@ -142,13 +166,108 @@ fn bench_sip(c: &mut Criterion) {
group.bench_with_input("string", &gen_strings(), |b, s| b.iter(|| black_box(siphash(s))));
}
+fn bench_map(c: &mut Criterion) {
+ #[cfg(feature = "std")]
+ {
+ let mut group = c.benchmark_group("map");
+ group.bench_function("aHash-alias", |b| {
+ b.iter(|| {
+ let hm: ahash::HashMap<i32, i32> = (0..1_000_000).map(|i| (i, i)).collect();
+ let mut sum = 0;
+ for i in 0..1_000_000 {
+ if let Some(x) = hm.get(&i) {
+ sum += x;
+ }
+ }
+ })
+ });
+ group.bench_function("aHash-hashBrown", |b| {
+ b.iter(|| {
+ let hm: hashbrown::HashMap<i32, i32> = (0..1_000_000).map(|i| (i, i)).collect();
+ let mut sum = 0;
+ for i in 0..1_000_000 {
+ if let Some(x) = hm.get(&i) {
+ sum += x;
+ }
+ }
+ })
+ });
+ group.bench_function("aHash-hashBrown-explicit", |b| {
+ b.iter(|| {
+ let hm: hashbrown::HashMap<i32, i32, RandomState> = (0..1_000_000).map(|i| (i, i)).collect();
+ let mut sum = 0;
+ for i in 0..1_000_000 {
+ if let Some(x) = hm.get(&i) {
+ sum += x;
+ }
+ }
+ })
+ });
+ group.bench_function("aHash-wrapper", |b| {
+ b.iter(|| {
+ let hm: ahash::AHashMap<i32, i32> = (0..1_000_000).map(|i| (i, i)).collect();
+ let mut sum = 0;
+ for i in 0..1_000_000 {
+ if let Some(x) = hm.get(&i) {
+ sum += x;
+ }
+ }
+ })
+ });
+ group.bench_function("aHash-rand", |b| {
+ b.iter(|| {
+ let hm: std::collections::HashMap<i32, i32, RandomState> = (0..1_000_000).map(|i| (i, i)).collect();
+ let mut sum = 0;
+ for i in 0..1_000_000 {
+ if let Some(x) = hm.get(&i) {
+ sum += x;
+ }
+ }
+ })
+ });
+ group.bench_function("aHash-default", |b| {
+ b.iter(|| {
+ let hm: std::collections::HashMap<i32, i32, BuildHasherDefault<AHasher>> =
+ (0..1_000_000).map(|i| (i, i)).collect();
+ let mut sum = 0;
+ for i in 0..1_000_000 {
+ if let Some(x) = hm.get(&i) {
+ sum += x;
+ }
+ }
+ })
+ });
+ }
+}
+
criterion_main!(benches);
+
+#[cfg(any(
+ all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
+ all(
+ any(target_arch = "arm", target_arch = "aarch64"),
+ any(target_feature = "aes", target_feature = "crypto"),
+ not(miri),
+ feature = "stdsimd"
+ )
+))]
+criterion_group!(benches, bench_ahash, bench_fx, bench_fnv, bench_sea, bench_sip);
+
+#[cfg(not(any(
+ all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes", not(miri)),
+ all(
+ any(target_arch = "arm", target_arch = "aarch64"),
+ any(target_feature = "aes", target_feature = "crypto"),
+ not(miri),
+ feature = "stdsimd"
+ )
+)))]
criterion_group!(
benches,
- bench_ahash,
bench_fallback,
bench_fx,
bench_fnv,
bench_sea,
- bench_sip
+ bench_sip,
+ bench_map,
);
diff --git a/vendor/ahash/tests/map_tests.rs b/vendor/ahash/tests/map_tests.rs
index be617a2e7..8d798a046 100644
--- a/vendor/ahash/tests/map_tests.rs
+++ b/vendor/ahash/tests/map_tests.rs
@@ -1,10 +1,11 @@
+#![cfg_attr(feature = "specialize", feature(build_hasher_simple_hash_one))]
+
use std::hash::{BuildHasher, Hash, Hasher};
+use ahash::RandomState;
use criterion::*;
use fxhash::FxHasher;
-use ahash::{AHasher, CallHasher, RandomState};
-
fn gen_word_pairs() -> Vec<String> {
let words: Vec<_> = r#"
a, ability, able, about, above, accept, according, account, across, act, action,
@@ -150,9 +151,18 @@ fn check_for_collisions<H: Hash, B: BuildHasher>(build_hasher: &B, items: &[H],
);
}
+#[cfg(feature = "specialize")]
#[allow(unused)] // False positive
fn hash<H: Hash, B: BuildHasher>(b: &H, build_hasher: &B) -> u64 {
- H::get_hash(b, build_hasher)
+ build_hasher.hash_one(b)
+}
+
+#[cfg(not(feature = "specialize"))]
+#[allow(unused)] // False positive
+fn hash<H: Hash, B: BuildHasher>(b: &H, build_hasher: &B) -> u64 {
+ let mut hasher = build_hasher.build_hasher();
+ b.hash(&mut hasher);
+ hasher.finish()
}
#[test]
@@ -169,10 +179,31 @@ fn test_bucket_distribution() {
check_for_collisions(&build_hasher, &sequence, 256);
}
+#[cfg(feature = "std")]
+#[test]
+fn test_ahash_alias_map_construction() {
+ let mut map = ahash::HashMap::default();
+ map.insert(1, "test");
+ use ahash::HashMapExt;
+ let mut map = ahash::HashMap::with_capacity(1234);
+ map.insert(1, "test");
+}
+
+#[cfg(feature = "std")]
+#[test]
+fn test_ahash_alias_set_construction() {
+ let mut set = ahash::HashSet::default();
+ set.insert(1);
+
+ use ahash::HashSetExt;
+ let mut set = ahash::HashSet::with_capacity(1235);
+ set.insert(1);
+}
+
fn ahash_vec<H: Hash>(b: &Vec<H>) -> u64 {
let mut total: u64 = 0;
for item in b {
- let mut hasher = AHasher::new_with_keys(1234, 5678);
+ let mut hasher = RandomState::with_seeds(12, 34, 56, 78).build_hasher();
item.hash(&mut hasher);
total = total.wrapping_add(hasher.finish());
}
diff --git a/vendor/ahash/tests/nopanic.rs b/vendor/ahash/tests/nopanic.rs
index d48ff559d..56f754cbe 100644
--- a/vendor/ahash/tests/nopanic.rs
+++ b/vendor/ahash/tests/nopanic.rs
@@ -1,5 +1,5 @@
-use ahash::{AHasher, CallHasher, RandomState};
-use std::hash::BuildHasher;
+use ahash::{AHasher, RandomState};
+use std::hash::{BuildHasher, Hash, Hasher};
#[macro_use]
extern crate no_panic;
@@ -8,8 +8,8 @@ extern crate no_panic;
#[no_panic]
fn hash_test_final(num: i32, string: &str) -> (u64, u64) {
use core::hash::Hasher;
- let mut hasher1 = AHasher::new_with_keys(1, 2);
- let mut hasher2 = AHasher::new_with_keys(3, 4);
+ let mut hasher1 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
+ let mut hasher2 = RandomState::with_seeds(3, 4, 5, 6).build_hasher();
hasher1.write_i32(num);
hasher2.write(string.as_bytes());
(hasher1.finish(), hasher2.finish())
@@ -24,6 +24,17 @@ struct SimpleBuildHasher {
hasher: AHasher,
}
+impl SimpleBuildHasher {
+ fn hash_one<T: Hash>(&self, x: T) -> u64
+ where
+ Self: Sized,
+ {
+ let mut hasher = self.build_hasher();
+ x.hash(&mut hasher);
+ hasher.finish()
+ }
+}
+
impl BuildHasher for SimpleBuildHasher {
type Hasher = AHasher;
@@ -35,11 +46,11 @@ impl BuildHasher for SimpleBuildHasher {
#[inline(never)]
#[no_panic]
fn hash_test_specialize(num: i32, string: &str) -> (u64, u64) {
- let hasher1 = AHasher::new_with_keys(1, 2);
- let hasher2 = AHasher::new_with_keys(1, 2);
+ let hasher1 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
+ let hasher2 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
(
- i32::get_hash(&num, &SimpleBuildHasher { hasher: hasher1 }),
- <[u8]>::get_hash(string.as_bytes(), &SimpleBuildHasher { hasher: hasher2 }),
+ SimpleBuildHasher { hasher: hasher1 }.hash_one(num),
+ SimpleBuildHasher { hasher: hasher2 }.hash_one(string.as_bytes()),
)
}
@@ -53,10 +64,7 @@ fn hash_test_random_wrapper(num: i32, string: &str) {
fn hash_test_random(num: i32, string: &str) -> (u64, u64) {
let build_hasher1 = RandomState::with_seeds(1, 2, 3, 4);
let build_hasher2 = RandomState::with_seeds(1, 2, 3, 4);
- (
- i32::get_hash(&num, &build_hasher1),
- <[u8]>::get_hash(string.as_bytes(), &build_hasher2),
- )
+ (build_hasher1.hash_one(&num), build_hasher2.hash_one(string.as_bytes()))
}
#[inline(never)]
@@ -68,5 +76,6 @@ fn hash_test_specialize_wrapper(num: i32, string: &str) {
fn test_no_panic() {
hash_test_final_wrapper(2, "Foo");
hash_test_specialize_wrapper(2, "Bar");
- hash_test_random_wrapper(2, "Baz");
+ hash_test_random(2, "Baz");
+ hash_test_random_wrapper(2, "Bat");
}