Skip to content

Commit 280aa74

Browse files
committed
Update performance.rs
1 parent 7e3931d commit 280aa74

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

crates/hash-sorted-map/benchmarks/performance.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,7 @@ fn bench_sort(c: &mut Criterion) {
403403

404404
group.bench_function("Vec::sort_unstable", |b| {
405405
b.iter(|| {
406-
let mut vec: Vec<_> = keys
407-
.iter()
408-
.enumerate()
409-
.map(|(i, &key)| (key, i))
410-
.collect();
406+
let mut vec: Vec<_> = keys.iter().enumerate().map(|(i, &key)| (key, i)).collect();
411407
vec.sort_unstable_by(|a, b| {
412408
let ha = hasher.hash_one(a.0);
413409
let hb = hasher.hash_one(b.0);
@@ -419,10 +415,8 @@ fn bench_sort(c: &mut Criterion) {
419415

420416
group.bench_function("HashSortedMap sort_by_hash", |b| {
421417
b.iter(|| {
422-
let mut map = HashSortedMap::with_capacity_and_hasher(
423-
keys.len(),
424-
IdentityBuildHasher::default(),
425-
);
418+
let mut map =
419+
HashSortedMap::with_capacity_and_hasher(keys.len(), IdentityBuildHasher::default());
426420
for (i, &key) in keys.iter().enumerate() {
427421
map.insert(key, i);
428422
}
@@ -443,7 +437,10 @@ fn bench_merge_sort(c: &mut Criterion) {
443437
.map(|_| {
444438
let mut rng = rand::rng();
445439
(0..KEYS_PER_MAP)
446-
.map(|_| folded_multiply(rng.random_range(0..1_000_000u32) as u64, 0x243f6a8885a308d3) as u32)
440+
.map(|_| {
441+
folded_multiply(rng.random_range(0..1_000_000u32) as u64, 0x243f6a8885a308d3)
442+
as u32
443+
})
447444
.collect()
448445
})
449446
.collect();
@@ -452,8 +449,7 @@ fn bench_merge_sort(c: &mut Criterion) {
452449
let hash_maps: Vec<_> = maps_data
453450
.into_iter()
454451
.map(|keys| {
455-
let mut map =
456-
HashSortedMap::with_hasher(IdentityBuildHasher::default());
452+
let mut map = HashSortedMap::with_hasher(IdentityBuildHasher::default());
457453
for key in keys {
458454
*map.entry(key).or_default() += 1u32;
459455
}
@@ -514,8 +510,9 @@ fn bench_merge_sort(c: &mut Criterion) {
514510
// ── 3. hashbrown HashMap merge, then sort into Vec ──────────────
515511
group.bench_function("hashbrown merge + Vec sort", |b| {
516512
b.iter(|| {
517-
let mut map =
518-
hashbrown::HashMap::<u32, u32, IdentityBuildHasher>::with_hasher(IdentityBuildHasher::default());
513+
let mut map = hashbrown::HashMap::<u32, u32, IdentityBuildHasher>::with_hasher(
514+
IdentityBuildHasher::default(),
515+
);
519516
for container in &hash_maps {
520517
for (&key, &value) in container {
521518
*map.entry(key).or_default() += value;
@@ -534,8 +531,9 @@ fn bench_merge_sort(c: &mut Criterion) {
534531
// ── 4. hashbrown HashMap merge only (no sort) ───────────────────
535532
group.bench_function("hashbrown merge", |b| {
536533
b.iter(|| {
537-
let mut map =
538-
hashbrown::HashMap::<u32, u32, IdentityBuildHasher>::with_hasher(IdentityBuildHasher::default());
534+
let mut map = hashbrown::HashMap::<u32, u32, IdentityBuildHasher>::with_hasher(
535+
IdentityBuildHasher::default(),
536+
);
539537
for container in &hash_maps {
540538
for (&key, &value) in container {
541539
*map.entry(key).or_default() += value;
@@ -580,10 +578,7 @@ fn bench_merge_sort(c: &mut Criterion) {
580578
group.bench_function("HashSortedMap merge presized", |b| {
581579
b.iter(|| {
582580
let mut map: HashSortedMap<u32, u32, _> =
583-
HashSortedMap::with_capacity_and_hasher(
584-
1_000_000,
585-
IdentityBuildHasher::default(),
586-
);
581+
HashSortedMap::with_capacity_and_hasher(1_000_000, IdentityBuildHasher::default());
587582
for container in &hash_maps {
588583
for (&key, &value) in container {
589584
*map.entry(key).or_default() += value;

0 commit comments

Comments
 (0)