Skip to content

Instantly share code, notes, and snippets.

@jeetsukumaran
Created February 18, 2010 03:32
Show Gist options
  • Save jeetsukumaran/307309 to your computer and use it in GitHub Desktop.
Save jeetsukumaran/307309 to your computer and use it in GitHub Desktop.
Comparison of performance of std::copy() vs. insert()
#include <iostream>
#include <vector>
int main(int, char* []) {
std::vector<int> a(10000000, 10);
std::vector<int> b;
b.reserve(10000000);
b.insert(b.end(), a.begin(), a.end());
}
#include <iostream>
#include <vector>
int main(int, char* []) {
std::vector<int> a(10000000, 10);
std::vector<int> b;
b.reserve(10000000);
std::copy(a.begin(), a.end(), std::back_inserter(b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment