// This benchmark suite contains some benchmarks along a set of dimensions: // Hasher: std default (SipHash) and crate default (AHash). // Int key distribution: low bit heavy, top bit heavy, and random. // Task: basic functionality: insert, insert_erase, lookup, lookup_fail, iter #![feature(test)]
externcrate test;
use test::{black_box, Bencher};
use hashbrown::hash_map::DefaultHashBuilder; use hashbrown::{HashMap, HashSet}; use std::{
collections::hash_map::RandomState,
sync::atomic::{self, AtomicUsize},
};
const SIZE: usize = 1000;
// The default hashmap when using this crate directly. type AHashMap<K, V> = HashMap<K, V, DefaultHashBuilder>; // This uses the hashmap from this crate with the default hasher of the stdlib. type StdHashMap<K, V> = HashMap<K, V, RandomState>;
// A random key iterator. #[derive(Clone, Copy)] struct RandomKeys {
state: usize,
}
impl Iterator for RandomKeys { type Item = usize; fn next(&mutself) -> Option<usize> { // Add 1 then multiply by some 32 bit prime. self.state = self.state.wrapping_add(1).wrapping_mul(3_787_392_781);
Some(self.state)
}
}
// Just an arbitrary side effect to make the maps not shortcircuit to the non-dropping path // when dropping maps/entries (most real world usages likely have drop in the key or value)
lazy_static::lazy_static! { staticref SIDE_EFFECT: AtomicUsize = AtomicUsize::new(0);
}
#[derive(Clone)] struct DropType(usize); impl Drop for DropType { fn drop(&mutself) {
SIDE_EFFECT.fetch_add(self.0, atomic::Ordering::SeqCst);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.