boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
101 stars 113 forks source link

vector assignment not using memcpy #74

Closed mglisse closed 6 years ago

mglisse commented 6 years ago

Hello, when copy-assigning a boost::container::vector<long> to another one of the same size, I would expect the code to end up as a call to memcpy (or possibly memmove). However, in boost, we end up in a hand-written loop in assign:

      for ( ; first != last && cur != end_it; ++cur, ++first){
         *cur = *first;
      }

This makes the following crude benchmark 4-5 times slower than using std::vector from libstdc++ or libc++.

#include <vector>
#include <boost/container/vector.hpp>
int main(int argc,char**){
#if 1
  typedef boost::container::vector<long> V;
#else
  typedef std::vector<long> V;
#endif
  V m(1024),n(1024);
  for(int k=0;k<1000000;++k) {
    n=m;
    m=n;
  }
  return m[argc];
}
igaztanaga commented 6 years ago

Thanks for the report. Fixed in commit:

https://github.com/boostorg/container/commit/62ee7403687849cc50654ad6870faceb03f8662f