|0.0.14||May 9, 2023|
|0.0.13||May 4, 2023|
|0.0.12||Apr 27, 2023|
#197 in Data structures
123 downloads per month
A much faster alternative of
for very small maps.
It is also faster than
and all others.
The smaller the map, the higher the performance.
It was observed that when a map contains more than 20 keys, it may be better to use the standard
the performance of
micromap::Map may start to degrade.
See the benchmarking results below.
WELCOME: Not all functions that you might expect to have in a map are implemented. I will appreciate if you contribute by implementing these missing functions.
First, add this to
[dependencies] micromap = "0.0.13"
Then, use it like a standard hash map... well, almost:
use micromap::Map; let mut m : Map<u64, &str, 10> = Map::new(); // allocation on stack m.insert(1, "foo"); m.insert(2, "bar"); assert_eq!(2, m.len());
Pay attention, here the map is created with an extra generic argument
10. This is
the total size of the map, which is allocated on stack when
::new() is called.
Map doesn't use heap at all. If more than ten keys will be
added to the map, it will panic.
There is a summary of a simple benchmark, where we compared
a few other Rust maps, changing the total capacity of the map (horizontal axis).
We applied the same interactions
to them and measured how fast they performed. In the following table,
the numbers over 1.0 indicate performance gain,
while the numbers below 1.0 demonstrate performance loss.
The experiment was performed on 09-05-2023. There were 1000000 repetition cycles. The entire benchmark took 321s.
As you see, the highest performance gain was achieved for the maps that were smaller than ten keys. For the maps of just a few keys, the gain was enormous.
How to Contribute
First, install Rust and then:
$ cargo test -vv
If everything goes well, fork repository, make changes, send us a pull request.
We will review your changes and apply them to the
master branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run
cargo test again. Also,
cargo fmt and
Also, before you start making changes, run benchmarks:
$ rustup run nightly cargo bench
Then, after the changes you make, run it again. Compare the results. If your changes degrade performance, think twice before submitting a pull request.