Hacker News new | ask | show | jobs
by marshray 4891 days ago
That's nice little demonstration of superior vector performance for a certain set of (very common) conditions:

# The value type (int in this case) is very small, in fact it's pointer-sized.

# This entire benchmark easily fits into L2 cache. The benchmark only goes up to 100000 elements, which for an int is only 390K. This can be an advantage of vector, but it's not necessarily such a slam-dunk in real-world programs where there are multiple data structures and other threads contending for the use of the cache.

# The value type has 'trivial' copy/move constructors and assignment operators. It's POD and outright memmove()-able.

# The benchmark code is only able to use list nodes one time. It doesn't take advantage of a list's ability to move items from one container to another without reallocation.

# The benchamark is thoroughly randomized. If it were more typical real-world data (such as supplied by another algorithm or even a malicious attacker) then you would want to consider the possibility of pathological access patterns arising.

So if you meet all of these conditions, definitely use a vector. If not, life is back to being complicated again.