[EMAIL PROTECTED] wrote:
> 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.
On my x86 system with gcc 4.0.3, they are both the same, so I guess it's
either a problem of the amd64 target or gcc 4.1.
BTW:
When I change the loop into:
for (vector<double>::iterator it = v.begin(); it != v.end(); ++it)
*it = 1;
it becomes faster (2.15 seconds versus 2.7 seconds).
_______________________________________________
help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus