Detailed comparison of STL container performance

  • 2020-04-02 01:39:50
  • OfStack

Write an int variable of 40M

The container memory Write it When removed from the head The vector                                                                 47 m                                       5   seconds                                                 The list                     739 m                   21 seconds                                 69   seconds                                                                   A deque                     217 m       4   seconds                                   2203 milliseconds The set                     821 m       137 seconds                                   The map                     905 m     136 seconds                                  

From the above data, it can be seen that the writing time of vector and deque is very fast, because they have few memory allocation times, the associated container and list are allocated one by one, and one by one allocation will also cause memory fragmentation and low memory utilization.

Every time you insert data in the middle, write an int variable of 40M

The container time A deque Too slow to know when to finish             The list 47 seconds        

Means that inserting or deleting a list in the middle is fast, and much slower in the head or tail than in the deque

Related articles: