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.

What HN saysHN commenters point to his hashmap benchmarks as a comparison of C++ hash table speed, and to an older terminal performance comparison.
27HN people shared it
14linked it in comments
16stories submitted
44story points
4 months agolast shared
2007people per year2026

Most-shared posts

  1. 1
    Comprehensive C++ Hashmap Benchmarks 2022
    9 people · 15 points · first shared 2022 · 1 comments on HN
  2. 2
  3. 3
    How to Generate Random Colors Programmatically
    5 people · 9 points · first shared 2009 · 2 comments 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 people · 3 points · first shared 2022 · discussion on HN
  6. 6
    Speedy Anagram Algorithm in Ruby Explained
    1 people · 1 points · first shared 2008 · discussion on HN
  7. 7
    Google Analytics Experiments Is Buggy
    1 people · 1 points · first shared 2016 · discussion on HN
  8. 8
    Human compact gnome theme
    1 people · first shared 2008
  9. 9
    Hashmap benchmarks 05 conclusion
    1 people · first shared 2020
  10. 10
    Hashmap benchmarks 02 01 result CtorDtorEmptyMap
    1 people · first shared 2020
  11. 11
    Trouble with fructose slides.pdf
    1 people · first shared 2013
  12. 12
  13. 13
  14. 14
    Clearlooks compact gnome theme
    1 people · first shared 2009

What HN people wrote when they linked it

Sesse__ · 2025-07-28
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.
martythemaniak · 2009-01-28
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/
tialaramex · 2023-03-03
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-resul… 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…
jeffbee · 2026-06-26
A more recent benchmark is https://martin.ankerl.com/2022/08/27/hashmap-bench-01/ However, it lacks the newer Boost stuff which is very fast. The Hopscotch map was interesting at the time but due to unfortunate timing was immediately outshone by absl::unordered_flat_map A.K.A. "Swiss tables", and there's been even more water under the bridge since then.
SPICLK2 · 2026-02-12
I don't see how you can blame terminal applications - they typically have been able to dump around 1Mb of output per second for decades. https://martin.ankerl.com/2007/09/01/comprehensive-linux-terminal-perf… Could the React rendering stack be optimised instead?
kccqzy · 2025-01-22
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/
camel-cdr · 2022-12-08
My guess for word_count and faq is that the C++ implementation uses std::unordered_map, which famously has quite poor performance. [0] [0] https://martin.ankerl.com/2019/04/01/hashmap-benchmarks-01-overview/
htfy96 · 2022-11-18
To anybody unfamiliar with recent progress, boost::unordered_flat_map is the fastest open-addressing hash map implementation in this field for C++. Coming out just several months ago, it outperforms absl::flat_hash_map and various other implementations benchmarked in https://martin.ankerl.com/2022/08/27/hashmap-bench-01/.
jcelerier · 2021-11-23
that's absolutely untrue in a lot of cases: https://stackoverflow.com/questions/36392583/is-an-unordered-map-reall… 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)
jessaustin · 2019-09-20
I've used the method described here [0] of simply incrementing hue by the golden ratio. You can generate dozens of colors that go well together yet are quite distinguishable. [0] https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-progr…
enscr · 2014-05-31
Related : "How to Generate Random Colors Programmatically" http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-progra…
Shorel · 2013-05-10
No, the author simply repeated old stuff. If all those 'reasonable' diets worked, the current obesity epidemic would not be in its worst point, as it is. Some evidence about sugar: http://www.youtube.com/watch?v=dBnniua6-oM http://www.youtube.com/watch?v=PRAwgdvhWHw http://martin.ankerl.com/wp-content/uploads/2012/01/trouble_with_fruct…
_gabe_ · 2022-08-09
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-R… [1]: https://benchmarkdotnet.org/articles/overview.html

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close