Is pushing integers into a vector, and then sorting the entire vector faster or slower than inserting the integers into a set, which sorts as you enter them. Sorry, I'm new to c++, and I'm not sure how to use the clock function. Could anyone help? Any help would be greatly appreciated. Thanks in advance.
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
vector<int> possibility1;
set<int> possibility2;
int main()
{
random_device rd;
mt19937 rng(rd());
uniform_int_distribution<int> uni(0,1000);
// possibility 1
for(int i = 0; i < 1000000; i++) {
int r = uni(rng);
possibility1.push_back(r);
}
// possibility 2
for(int j = 0; j < 1000000; j++) {
int r = uni(rng);
possibility2.insert(r);
}
}
EDIT
For this case, the difference in time doesn't really matter, but if I have large classes with a lot of private variables, and a make a vector/set of objects (with a compare function, too), which one would be faster?