Using this simple test program, it seems that using the operator[] for
vector access is slower than accessing through a double pointer array
access.

#include <vector>
using namespace std;
int main()
{
  vector<double> v(10000);
  const size_t len = v.size();
  for (size_t j = 0; j < 100000; ++j)
  {
    double *p = &v[0];
    for (size_t i = 0; i < v.size(); ++i)
      v[i] = 1;
//      p[i]=1;


  }

}

Running using v[i] in the code above results in about 2.5 sec run time.
 Running with p[i] instead of v[i] results in about 1.5 sec run time on
an amd 64.  This is with gcc version 4.1 and using -O3.

I find this result suprising for such a simple data type.  Is there any
way to optimize this for vector access?

Regards,

Juan

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to