Intuition for `HashMap` vs `BTreeMap` performance
I've been hearing conflicting advice about when to use HashMap vs BTreeMap in Rust.
BTreeMaphas ordering, which is its main advantage.- Some say
BTreeMapis good for small sets (< 1000 elements) but gets worse after that. - Others claim that for very small sets, even linear search outperforms the binary search that
BTreeMapuses (possibly mentioned in https://www.youtube.com/watch?v=DMQ_HcNSOAI), which makes me think even for small sets aHashMapwould be better (contradicting previous point). - With a fast hasher, maybe performance differences are less significant?
I'm not sure if there's a clear-cut rule for when to use each. Has anyone got some practical insights or intuition?
Some discussions I've found:
Is there really no good intuition for this choice, or am I missing something obvious?