Created
February 18, 2010 03:32
-
-
Save jeetsukumaran/307309 to your computer and use it in GitHub Desktop.
Comparison of performance of std::copy() vs. insert()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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