[討論] VC2010 V.S Linux (STL vector)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC2010 && Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
#include <vector>
問題(Question):
VC 2010 的vector
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <vector>
#include <time.h>
#include <stdlib.h>
#define SIZE 10000000
float array[SIZE];
using namespace std;
int main(){
int i;
srand(time(NULL));
time_t s,e;
s = time(NULL);
int l;
vector<float> array;
for(i=0;i<SIZE;i++){
array[i] = ((float)(rand()%10000)/(float)10000);
array.push_back(((float)(rand()%10000)/(float)10000));
}
e = time(NULL);
cout <<"time passed is : "<<e - s << endl;
return 0;
}
-------
我先在Linux 平台上分別跑了兩次這隻程式(一支跑綠色code 一隻跑紅色code)
結果沒有意外的 時間都差不多是一秒左右
然後再VC2010 跑一模一樣的程式
結果直接用array 的紅色程式也是跑了差不多一秒
但是用STL的vector 竟然跑了三~四秒....
明明tutorial 上面寫vector.push 也是 amortized const time
結果在VC 上面跑 竟然慢到三倍...
這個結果讓我覺得很無言
微軟是對STL 做了甚麼奇怪的事情嗎 = =
好離譜0.0
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.244.131
→
06/26 18:06, , 1F
06/26 18:06, 1F
推
06/26 18:46, , 2F
06/26 18:46, 2F
→
06/26 18:49, , 3F
06/26 18:49, 3F
→
06/26 18:49, , 4F
06/26 18:49, 4F
→
06/26 20:54, , 5F
06/26 20:54, 5F
推
06/26 21:36, , 6F
06/26 21:36, 6F
→
06/26 21:47, , 7F
06/26 21:47, 7F
→
06/26 21:48, , 8F
06/26 21:48, 8F
→
06/26 21:49, , 9F
06/26 21:49, 9F
推
06/26 21:54, , 10F
06/26 21:54, 10F
→
06/26 21:55, , 11F
06/26 21:55, 11F
→
06/26 21:56, , 12F
06/26 21:56, 12F
→
06/26 21:57, , 13F
06/26 21:57, 13F
→
06/26 21:58, , 14F
06/26 21:58, 14F
→
06/27 16:32, , 15F
06/27 16:32, 15F
→
06/27 22:56, , 16F
06/27 22:56, 16F
→
06/27 22:56, , 17F
06/27 22:56, 17F