Looking at this interesting talk:
CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
He mentions around minute 38:32 that
void Benchmark_Slow(int iters) {
std::unordered_map<string, int> m;
std::pair<const string, int> p = {};
while (iters--) m.insert(p)
}
is ~2x slower than the following variation
void Benchmark_Fast(int iters) {
std::unordered_map<string, int> m;
const std::pair<const string, int> p = {};
while (iters--) m.insert(p)
}
I am still thinking about why the &&
overload (1) would be selected.
std::pair<iterator,bool> insert( value_type&& value ); (1)
std::pair<iterator,bool> insert( const value_type& value ); (3)
where value_type
is std::pair<const Key, T>
.
After all, we are not moving the values, so in my understanding, the expression p
should be an lvalue and not an x/prvalue, is that right? Can somebody enlighten me?
You don't take the problematic overloads:
P
deduced asvalue_type&
.