4 ms·
I think the issue here is that std::list is an extremely bad implementation of a linked list. One of the nice advantages of linked lists as opposed to vectors,
by Peaker 13y ago
I think the issue here is that std::list is an extremely bad implementation of a linked list.
One of the nice advantages of linked lists as opposed to vectors, is that you can avoid allocations, and std::list doesn't facilitate this advantage unless your data is only inside a single list. Another advantage of proper lists, is that it is very cheap to do things like remove an item from multiple lists it is in. std::list requires maintaining extra list iterators in the item for this, which is both difficult and wasteful.
If std::list is the benchmark for lists, vectors indeed beat them handily for virtually any task.
But compare Linux's intrusive linked list (Linux's list.h) with vectors for the many many tasks that fit these lists' use cases, and vectors are going to lose on all fronts, including cache misses.