Iterator access performance for STL map vs. vector?

前端 未结 6 1476
星月不相逢
星月不相逢 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:31

    This link has a nice table of performance for various operations on all of the STL containers.

    Generally speaking, if you need to do a lot of inserting, removing or searching based on a key then the map is the way to go.

    If you only need to set up the container once and then access it like an array then use a vector.

    EDIT: Performance table of STL container operations:

    enter image description here

提交回复
热议问题