Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2000-02-05 13:54:49

Thanks for pushing on this. Here are my timings for the program shown below.

What I am seeing in this test is that the time to allocate the long vanishes
in the overhead of allocating and filling the vector or list, and that the
size of the smart pointer makes a difference when you start copying them
around a lot, as in sorting the vector.

testing 1000000 int*
fill vector: 1046
sort vector: 1000
fill list: 2406
sort list: 20125

testing 1000000 shared_ptr<int>
fill vector: 2000
sort vector: 6093
fill list: 3062
sort list: 25047

testing 1000000 linked_ptr<int>
fill vector: 2422
sort vector: 8047
fill list: 3375
sort list: 26062

int main(int argc, char** argv) {
   const int N = atoi(argv[1]);

   #if defined(RAW)
      typedef int* ptr_int;
      printf("testing %d int* \n", N);
   #elif defined(LINKED)
      typedef linked_ptr<int> ptr_int;
      printf("testing %d linked_ptr<int>\n", N);
      typedef shared_ptr<int> ptr_int;
      printf("testing %d shared_ptr<int>\n", N);

   { clock_t start = clock();
      vector<ptr_int> container(N);;
      for (int i = 0; i < N; i++ )
         container[i] = ptr_int(new int(rand()));
      printf("fill vector: %ld\n",
             ((long)clock() - start)*1000/CLOCKS_PER_SEC);
      start = clock();
      sort(container.begin(), container.end());
      printf("sort vector: %ld\n",
              ((long)clock() - start)*1000/CLOCKS_PER_SEC);
   { clock_t start = clock();
      list<ptr_int> container;
      for (int i = 0; i < N; i++ )
         container.push_back(ptr_int(new int(rand())));
      printf("fill list: %ld\n",
             ((long)clock() - start)*1000/CLOCKS_PER_SEC);
      start = clock();
      printf("sort list: %ld\n",
             ((long)clock() - start)*1000/CLOCKS_PER_SEC);

   return 0;

Boost list run by bdawes at, gregod at, cpdaniel at, john at