‹ BackHN Continuity

Thread

Writing Efficient C++ Code (2013)

176 points · 161 comments · ibobev

  1. asveikau · · focus · HN ↗
    This article reminds me of performance advice I was starting to see in the 2000s decade. Basically it was to not introduce a bunch of pointer heavy data structures to get lower algorithmic complexity. Stuff it all into a vector. You will use some algorithms that the computer science textbook will say it's slower, but if it fits all in cache it doesn't matter. The cache misses following pointers all over town hurts you more.
    1. bluGill · · focus · HN ↗
      While this advice isn't wrong, it is misleading. In my benchmarks std::map beats vector after 9 elements. Less than that and linear search is better but branch prediction and cache loading is very good.

      Run your own benchmarks on your own data of course. Also map is not considered the best key value store.

      1. someonebaggy · · focus · HN ↗
        That is not a plausible result, sorry. Perhaps you're using the painfully slow MSVC debug mode vector?
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.