forked from contain-rs/hashmap2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code for gathering stats about extremely slow HashMap operations
- Loading branch information
Showing
5 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extern crate hashmap2; | ||
extern crate rand; | ||
|
||
use hashmap2::HashMap; | ||
use rand::Rng; | ||
|
||
fn main() { | ||
let mut map: HashMap<i32, ()> = HashMap::new(); | ||
assert_eq!(map.len(), 0); | ||
let mut rng = rand::weak_rng(); | ||
let mut iter = rng.gen_iter(); | ||
let len = 2 << 20; | ||
let usable_cap = (len as f32 * 0.833) as usize; | ||
let mut stats = vec![]; | ||
for _ in 0..10000 { | ||
while map.len() < usable_cap { | ||
map.insert(iter.next().unwrap(), ()); | ||
} | ||
map.stats(&mut stats); | ||
map.clear(); | ||
} | ||
for (i, (displacement, forward_shift)) in stats.into_iter().enumerate() { | ||
println!("{}: {}\t{}", i, displacement, forward_shift); | ||
} | ||
println!("map len={:?} capacity={:?}", map.len(), map.capacity()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters