Skip to content

Conversation

@philnik777
Copy link
Contributor

@philnik777 philnik777 commented Sep 3, 2025

------------------------------------------------------------------------------------------------
Benchmark                                                                    old             new
------------------------------------------------------------------------------------------------
std::unordered_map<int, int>::find(key) (existent)/0                    0.007 ns        0.007 ns
std::unordered_map<int, int>::find(key) (existent)/32                    1.36 ns         1.01 ns
std::unordered_map<int, int>::find(key) (existent)/1024                  1.31 ns         1.15 ns
std::unordered_map<int, int>::find(key) (existent)/8192                  1.50 ns         1.16 ns
std::unordered_map<int, int>::find(key) (non-existent)/0                0.321 ns        0.318 ns
std::unordered_map<int, int>::find(key) (non-existent)/32                1.34 ns         1.36 ns
std::unordered_map<int, int>::find(key) (non-existent)/1024              1.08 ns         1.11 ns
std::unordered_map<int, int>::find(key) (non-existent)/8192              1.15 ns         1.21 ns
std::unordered_set<int>::find(key) (existent)/0                         0.007 ns        0.007 ns
std::unordered_set<int>::find(key) (existent)/32                         1.42 ns         1.07 ns
std::unordered_set<int>::find(key) (existent)/1024                       1.32 ns        0.962 ns
std::unordered_set<int>::find(key) (existent)/8192                       1.51 ns         1.17 ns
std::unordered_set<int>::find(key) (non-existent)/0                     0.325 ns        0.328 ns
std::unordered_set<int>::find(key) (non-existent)/32                     1.43 ns         1.31 ns
std::unordered_set<int>::find(key) (non-existent)/1024                   1.37 ns         1.26 ns
std::unordered_set<int>::find(key) (non-existent)/8192                   1.33 ns         1.21 ns
std::unordered_multimap<int, int>::find(key) (existent)/0               0.007 ns        0.007 ns
std::unordered_multimap<int, int>::find(key) (existent)/32               1.36 ns         1.05 ns
std::unordered_multimap<int, int>::find(key) (existent)/1024             1.45 ns        0.908 ns
std::unordered_multimap<int, int>::find(key) (existent)/8192             1.37 ns        0.922 ns
std::unordered_multimap<int, int>::find(key) (non-existent)/0           0.332 ns        0.344 ns
std::unordered_multimap<int, int>::find(key) (non-existent)/32           1.30 ns         1.28 ns
std::unordered_multimap<int, int>::find(key) (non-existent)/1024         1.18 ns         1.39 ns
std::unordered_multimap<int, int>::find(key) (non-existent)/8192         1.05 ns         1.33 ns
std::unordered_multiset<int>::find(key) (existent)/0                    0.007 ns        0.007 ns
std::unordered_multiset<int>::find(key) (existent)/32                    1.29 ns        0.981 ns
std::unordered_multiset<int>::find(key) (existent)/1024                  1.28 ns         1.05 ns
std::unordered_multiset<int>::find(key) (existent)/8192                  1.33 ns         1.22 ns
std::unordered_multiset<int>::find(key) (non-existent)/0                0.332 ns        0.332 ns
std::unordered_multiset<int>::find(key) (non-existent)/32                1.47 ns         1.29 ns
std::unordered_multiset<int>::find(key) (non-existent)/1024              1.09 ns         1.11 ns
std::unordered_multiset<int>::find(key) (non-existent)/8192              1.34 ns         1.21 ns

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super convinced. I find the optimization a bit ad-hoc and the results are not super significant. I think I'd rather explore the other optimization you mentioned where you don't store the hash at all in the node if the hash function desugars to identity.

@philnik777 philnik777 closed this Oct 15, 2025
@philnik777 philnik777 deleted the optimize_hash_table_find branch October 15, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants