Question: when using C++ vector, time spent is 718 milliseconds,
while when I use Array, time is almost 0 milliseconds.

Why so much performance difference?

```
int _tmain(int argc, _TCHAR* argv[])
{
const int size = 10000; 
clock_t start, end; 
start = clock();
vector<int> v(size*size); 
for(int i = 0; i < size; i++)
{  
    for(int j = 0; j < size; j++)
    {   
        v[i*size+j] = 1;  
    } 
} 
end = clock();
cout<< (end - start)
    <<" milliseconds."<<endl; // 718 milliseconds

int f = 0;
start = clock(); 
int arr[size*size]; 
for(int i = 0; i < size; i++)
{  
    for(int j = 0; j < size; j++)
    {   
        arr[i*size+j] = 1;  
    } 
} 
end = clock();
cout<< ( end - start)
    <<" milliseconds."<<endl; // 0 milliseconds
return 0;
}

```

Answer: 
If you are compiling this with a Microsoft compiler, to make it a fair comparison you need to switch off iterator security checks and iterator debugging, by defining \_SECURE\_SCL=0 and \_HAS\_ITERATOR\_DEBUGGING=0.

Secondly, the constructor you are using initialises each vector value with zero, and you are not memsetting the array to zero before filling it. So you are traversing the vector twice.

Try:

```
vector<int> v; 
v.reserve(size*size);

```
When profiling code, make sure you are comparing similar things.

```
vector<int> v(size*size); 

```

initializes each element in the vector,

```
int arr[size*size]; 

```

doesn't. Try

```
int arr[size * size];
memset( arr, 0, size * size );

```

and measure again...