This code takes about 20 seconds in my VS2012, but only 1.x seconds in G++. Both in win8 x64 and compiled with default options.
list<double> items;
for(int i=0;i<10000000;i++){
items.push_back(rand());
}
cout<<"done"<<endl;
Is it something about memory allocation? It takes 3~5 seconds to release memory after the ouput in VC++ in my machine, and even more than 1 minute in my firend's (win7 x64).
Hmm...I expanded your code to include timing:
#include <list>
#include <iostream>
#include <time.h>
#include <stdlib.h>
int main() {
std::list<double> items;
clock_t start = clock();
for(int i=0;i<10000000;i++){
items.push_back(rand());
}
clock_t finish = clock();
std::cout << "Time: " << double(finish-start)/CLOCKS_PER_SEC << "\n";
return 0;
}
I compiled with VC++ using: cl /O2b2 /GL test_list.cpp
Likewise, I compiled with g++, using: g++ -O3 test_list.cpp
Then I ran the two.
With VC++ I got: Time: 1.293
.
With g++ I got: Time: 1.313
.
That's a small enough difference that I think I'd need to test quite a bit more to be at all certain of saying VC++ produced significantly faster code, but I think it's enough to support a conclusion that VC++ is not producing significantly slower code.
You need to turn on optimization for timing results to mean anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With