Skip to content
HomeVideosBooksBlogs
AllTop postsTopics
Podcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    M

    Martin Ankerl

    martin.ankerl.com · Personal blog · on HN since 2007

    Martin Ankerl writes about C++ performance, mainly hashmap benchmarks, along with small algorithm and programming posts.

    Visit blogRSSHN submissions
    Systems & PerformanceProgramming
    What HN says

    HN commenters point to his hashmap benchmarks as a comparison of C++ hash table speed, and to an older terminal performance comparison.

    Stats for nerds
    27HN people shared it
    16linked in comments
    44story points
    Jun 2026last shared
    2009people per year2026

    Top posts on HN

    1. 1
      Comprehensive C++ Hashmap Benchmarks 2022
      9 people · 15 points · first shared 2022 · 1 comments on HN
    2. 2
      How to Generate Random Colors Programmatically
      5 people · 9 points · first shared 2009 · 2 comments on HN
    3. 3
      Hashmaps Benchmarks – Finding the Fastest, Memory Efficient Hashmap
      6 people · 8 points · first shared 2019 · Discussion on HN
    4. 4
      Optimized pow() approximation for Java, C / C++, and C#
      2 people · 7 points · first shared 2007 · Discussion on HN
    5. 5
      Hashmaps Benchmarks – Insert and Erase 100M integers
      1 person · 3 points · first shared 2022 · Discussion on HN
    6. 6
      Google Analytics Experiments Is Buggy
      1 person · 1 points · first shared 2016 · Discussion on HN
    7. 7
      Speedy Anagram Algorithm in Ruby Explained
      1 person · 1 points · first shared 2008 · Discussion on HN
    8. 8
      Comprehensive linux terminal performance comparison
      1 person · first shared 2026
    9. 9
      Hashmap benchmarks 04 03 result RandomFind 500000
      1 person · first shared 2022
    10. 10
      Hashmap benchmarks 02 01 result CtorDtorEmptyMap
      1 person · first shared 2020

    What HN people wrote when they linked it

    • tialaramexMar 2023

      As you presumably know std::unordered_map is essentially obliged to be a particular flavour of hash map which I'd say values simplicity of implementation over any performance metrics but which also provides certain iterator invalidation semantics which C++ programs could in principle come to rely on (and hence it cannot be swapped for a new structure).

      Turns out for this structure hash quality just doesn't matter very much. The identity function is all you need for mediocre results, and a really great hash produces only slightly improved results with this data structure, yet running the hash costs performance so why bother ?

      But a modern hash map structure actually relies on that quality for reasonable performance.

      https://martin.ankerl.com/2022/08/27/hashmap-bench-01/#benchmark-results-table

      Ask that table about std::unordered_map - notice the fancier hashes make it worse (bigger numbers are worse, relative to 100 is the best) but not that much worse. It's always poor, it just varies as to whether it's very poor.

      Now, ask it about absl::flat_hash_map - for Abseil's own hashes the results range from very good to mediocre, and likewise other modern high quality hashes, but for std::hash it's so awful most benchmarks don't finish, shown as - instead of a number.

      You can try to detect this, but this is a fundamentally a QoI problem. Why even provide this rubbish hash function in the standard library? This is a lesson the C++ standard library refuses to learn, if you…

    • _gabe_Aug 2022

      It looks like caching definitely skewed the results a bit. You can take a look at the linked code yourself. Worst case was still only around 80 nanoseconds which is definitely slower, but still orders of magnitude faster than "sub 5 micros".

      Don't take my word for it though, you can take a look at the Robin Hood benchmarks[0]. Robin Hood unordered map is a competitive hash map that's performed much better than the STL for me in many cases. They average a 4 nanosecond lookup speed for a hash map with 2000 elements and an integer key.

      > Did you benchmark against Java's HashMap?

      I benchmarked against C#, which has a runtime that performs similar if not better than the JVM. The C# code was a ~~few microseconds~~ around 130 nanoseconds. Which is still very fast, but up to 100x slower. (And yes, this was after warming up the code. I used benchmark dot net[1] here.). This is a really easy benchmark to set up. If you doubt me you can write a couple of benchmarks in under an hour and compare yourself.

      [0]: https://martin.ankerl.com/2019/04/01/hashmap-benchmarks-04-03-result-RandomFind_500000/

      [1]: https://benchmarkdotnet.org/articles/overview.html

    • martythemaniakJan 2009

      Ubuntu/Gnome user here:

      You know, I really love the idea of KDE, their philosophy and recent developments and progress they've made... but I've tried KDE 4.1 and I can't make myself use it. Its superficial but I think its their visual style that I find somewhat off-putting.

      I wish I had the time/drive and visual design skills to build a complete KDE 4.x theme, something far visually smaller, simpler and more minimalistic than what they have. I really like Google Chrome's motto ("Content not Chrome"), but haven't found a KDE look to satisfy that. The default ubuntu theme is also bad from this perspective, but it can be brought under control with this: http://martin.ankerl.com/2007/11/04/clearlooks-compact-gnome-theme/

    • Sesse__Jul 2025

      The absl tables (the canonical Swisstables) are good, but not the fastest. Of course, everything will depend on your hardware, compiler and usage patterns, but if you look at an all-round benchmark like https://martin.ankerl.com/2022/08/27/hashmap-bench-01/, they're about in the middle of the pack even when picking the best-working hash functions (and really bad if you happen to have a bad one). This mirrors my own experience.

      Of course, absl tables will have been improved since 2022, but there are many competitors that have improved as well. And you could argue “well, who ever copies or iterates over a map”, but even if you take away those categories, they're not a clear leader really anywhere else either.

    • jcelerierNov 2021

      that's absolutely untrue in a lot of cases: https://stackoverflow.com/questions/36392583/is-an-unordered-map-really-faster-than-a-map-in-practice

      of course one can always find faster, drop-in replacement libraries: https://martin.ankerl.com/2019/04/01/hashmap-benchmarks-01-overview/

      e.g. replacing std::unordered_map with robin_hood::hash_map makes the above C++ code go from 1.2 seconds to 0.5 seconds on my machine (std::map is around 1.3/1.4 seconds for libstdc++).

      (though as others said, this test is in big part a test of std::string performance... replacing strings by int make times go down to ~0.1s here)

    • kccqzyJan 2025

      My understanding of the word "quick" in the title is that this code is quick to write. But then this brings up the question of why. Why do we prioritize code that is easy to write, which presumably means it needs to be written over and over again. Is this a reflection of the sad state of C library packaging?

      A quick perusal of the hashmap landscape[0] in C++ shows a vibrant ecosystem where newer and faster implementations appear every year or so.

      [0]: https://martin.ankerl.com/2022/08/27/hashmap-bench-01/

    Related

    Eric Nieblerericniebler.com22 people

    C++20 Ranges

    Eric Niebler
    Personal · last shared 2024
    Emil Ernerfeldtilikebigbits.com53 people

    The Myth of RAM (2014)

    Emil Ernerfeldt
    Personal · last shared 2026
    Probably Danceprobablydance.com74 people

    Fibonacci Hashing: The Optimization That the World Forgot

    Probably Dance
    Personal · last shared 2026
    Bannaliabannalia.blogspot.com22 people

    Inside boost::unordered_flat_map

    Bannalia
    Personal · last shared 2026
    C++ Storiescppstories.com35 people

    Embracing Modern C++ Safely, Book Review

    C++ Stories
    Personal · last shared 2026
    Ralf Jungralfj.de99 people

    There is no memory safety without thread safety

    Ralf Jung
    Personal · last shared 2026
    Andrzej's C++ blogakrzemi1.wordpress.com35 people

    A bug in GCC that may cause memory leaks in valid C++ programs

    Andrzej's C++ blog
    Personal · last shared 2025
    1024cores1024cores.net36 people

    Lockfree Algorithms (2010)

    1024cores
    Personal · last shared 2025