-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Insert a key-value pair into the map without checking if the key already exists in the map. This operation is safe if a key does not exist in the map. However, if a key exists in the map already, the behavior is unspecified: this operation may panic, or any following operation with the map may panic or return arbitrary result. This operation is faster than regular insert, because it does not perform lookup before insertion. This operation is useful during initial population of the map. For example, when constructing a map from another map, we know that keys are unique. Simple benchmark of `insert` vs `insert_unique_unchecked` included: ``` test insert ... bench: 14,929 ns/iter (+/- 2,222) test insert_unique_unchecked ... bench: 11,272 ns/iter (+/- 1,172) ```
- Loading branch information
1 parent
35b36eb
commit dd3b2d8
Showing
4 changed files
with
89 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![feature(test)] | ||
|
||
extern crate test; | ||
|
||
use test::Bencher; | ||
|
||
use indexmap::IndexMap; | ||
|
||
#[bench] | ||
fn insert(b: &mut Bencher) { | ||
b.iter(|| { | ||
let mut m = IndexMap::with_capacity(1000); | ||
for i in 0..1000 { | ||
m.insert(i, i); | ||
} | ||
m | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn insert_unique_unchecked(b: &mut Bencher) { | ||
b.iter(|| { | ||
let mut m = IndexMap::with_capacity(1000); | ||
for i in 0..1000 { | ||
m.insert_unique_unchecked(i, i); | ||
} | ||
m | ||
}); | ||
} |
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