Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vector assignment not using memcpy #74

Closed
mglisse opened this issue Jun 15, 2018 · 1 comment
Closed

vector assignment not using memcpy #74

mglisse opened this issue Jun 15, 2018 · 1 comment

Comments

@mglisse
Copy link

mglisse commented Jun 15, 2018

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
Copy link
Member

Thanks for the report. Fixed in commit:

62ee740

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants