Re: Vectors vs Arrays performance
In article <xsKdnfOpwfzOpd7WnZ2dnUVZ7sqdnZ2d@giganews.com>,
Leigh Johnston <leigh@i42.co.uk> wrote:
For some reason the optimizer is not optimizing out the call to size() for
vecarray which is interesting.
If I change the loops to
for (size_t j = 0; j < VSIZE; ++j)
v[j] = j;
I get the following:
vector: 5.3602 seconds
vecarray: 5.2557 seconds
Same here. It improves vecarray. I now get 4.70s for both.
Seems like my std::vector is more performant than yours :-)
Interestingly, if I increase the size of the array, this make vecarray
lag behind again. The results also become less stable but this would
seem to show that large vecarray on the stack are less performant than
std::vectors :
vector: 8.15 s
vecarray: 8.39 s
vector: 8.21 s
vecarray: 8.55 s
vector: 7.71 s
vecarray: 8.39 s
vector: 7.45 s
vecarray: 8.18 s
If I reduce the size of the array and increase LOOP, the reverse
happens and vecarray becoems a bit more performant.
size_t const VSIZE = 1000000;
size_t const LOOP = 10000;
int main()
{
lib::vecarray<int, VSIZE> va;
va.resize(VSIZE);
std::vector<int> v;
v.resize(VSIZE);
{
std::cout << "vector: ";
boost::progress_timer t;
for (size_t i = 0; i < LOOP; ++i)
{
for (size_t j = 0; j < VSIZE; ++j)
v[j] = j;
}
}
{
std::cout << "vecarray: ";
boost::progress_timer t;
for (size_t i = 0; i < LOOP; ++i)
{
for (size_t j = 0; j < VSIZE ; ++j)
va[j] = j;
}
}
}
Examples and counter-examples.
"There is no spoon" "There is no pointer"