Here is the code to test.
Tuple test:
using namespace std; int main(){ vector<tuple<int,int>> v; for (int var = 0; var < 100000000; ++var) { v.push_back(make_tuple(var, var)); } }
Para test:
#include <vector> using namespace std; int main(){ vector<pair<int,int>> v; for (int var = 0; var < 100000000; ++var) { v.push_back(make_pair(var, var)); } }
I took a time measurement using the Linux time command. Results:
| | -O0 | -O2 | |:------|:-------:|:--------:| | Pair | 8.9 s | 1.60 s | | Tuple | 19.8 s | 1.96 s |
I am wondering why there is such a big difference between the two data structures in O0, since they should be very similar. There is a slight difference in 02.
Why is the difference in O0 so big, and why is there any difference?
EDIT:
Code with v.resize ()
Couple:
#include <vector> using namespace std; int main(){ vector<pair<int,int>> v; v.resize(100000000); for (int var = 0; var < 100000000; ++var) { v[var] = make_pair(var, var); } }
Tuple:
#include<tuple> #include<vector> using namespace std; int main(){ vector<tuple<int,int>> v; v.resize(100000000); for (int var = 0; var < 100000000; ++var) { v[var] = make_tuple(var, var); } }
Results:
| | -O0 | -O2 | |:------|:-------:|:--------:| | Pair | 5.01 s | 0.77 s | | Tuple | 10.6 s | 0.87 s |
EDIT:
My system
g++ (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7) GLIBCXX_3.4.19
performance c ++ 11 std-pair stdtuple
Aleksandar Nov 11 '14 at 11:30 2014-11-11 11:30
source share