Insertion

If your performance-critical path contains code to insert a large number of elements into a container, what container should you use? To gain some insight into that question we will give some containers a workout and discuss the results. The insertion exercise will insert a million random elements into an array, vector, list, and multiset. Each insertion test takes three parameters:

  • A pointer to the target container under test

  • A pointer to a data array of elements to be inserted

  • The size of the data array

The insertion tests for the various containers are given here:

 template <class T> void arrayInsert (T *a, T *collection, int size) { for (int k =0; k < size; k++) { a[k] = collection[k]; } } template <class T> void vectorInsert (vector<T> ...

Get Efficient C++ Performance Programming Techniques now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.