Iterator access performance for STL map vs. vector?

前端 未结 6 1463
星月不相逢
星月不相逢 2021-02-05 17:15

What is the performance difference between using an iterator to loop through an STL map, versus a vector? I\'d like to use the map key for insertion, deletion, and some accesses

6条回答
  •  囚心锁ツ
    2021-02-05 17:32

    Browsing the tree is not expensive (grosso modo like following a linked list), you won't benefit from the cache as much with a vector, but generally it's what you do when you iterate that is expensive, not the iteration itself.

    Could you tell us more about what you expect to do when you iterate through the whole map?

提交回复
热议问题