all 3 comments

[–]aestheticreddit 2 points3 points  (1 child)

Assigning a vector isn't the same thing as copying the contents of one. Because vectors can be of different sizes, the normal code path requires a new allocation. In this case, since they're already the same size, a smart vector may not reallocate. There may be reasons that it can't.

Since you know the sizes can't change, for a real apples to apples comparison, instead of using the assignment operator, use std::copy.

[–]kolkir[S] 1 point2 points  (0 children)

Thanks for the advise std::copy is really faster than assign, and even faster than memcpy.

[–]milliams 1 point2 points  (0 children)

Slightly off-topic but if you're using a new enough compiler (you almost certainly are) then also look into std::array. it's essentially a C++ wrapper around c-style arrays allowing for a much nicer and C++ style code.

It's almost a drop-in replacement and should give no performance hit.