I am using the std::set
container to store some scalar integer values. I've noticed that the insert
operation is slow when I call it in a loop. How can I make it faster?
Here is some representative code:
std::set<unsigned long> k;
unsigned long s = pow(2,31);
for(unsigned long i = 0; i < s; i++){
k.insert(i);
}
std::cout << k.size() << std::endl;
This code takes a very long time to execute. How can I modify this code (and/or change my algorithm) in order to make it run faster?