Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created June 11, 2013 18:33
Show Gist options
  • Save bananu7/5759466 to your computer and use it in GitHub Desktop.
Save bananu7/5759466 to your computer and use it in GitHub Desktop.
List vs Vector benchmark bajtek@bajtek-VirtualBox:~/list_vs_vector$ time ./list real 0m0.116s user 0m0.080s sys 0m0.020s bajtek@bajtek-VirtualBox:~/list_vs_vector$ time ./vec real 0m0.107s user 0m0.068s sys 0m0.024s
1 #include <list>
2 #include <vector>
3
4 const unsigned n = 1000000;
5
6 int main () {
7 std::list<int> list_a;
8 for (int i = 1; i <= 1000000; ++i)
9 list_a.push_back(i);
10 std::list<int> list_b;
11 for (int i = 1000001; i <= 2000000; ++i)
12 list_b.push_back(i);
13
14 std::vector<int> v_a;
15 for (int i = 1; i <= n; ++i)
16 v_a.push_back(i);
17
18 std::vector<int> v_b;
19 for (int i = n+1; i <= 2*n; ++i)
20 v_b.push_back(i);
21
22 list_a.splice(list_a.end(), list_b);
23 // std::copy(v_b.begin(), v_b.end(), std::back_inserter(v_a));
24 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment