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: 
Change assignment to eg. `arr[i*size+j] = i*j`, or some other non-constant expression. I think compiler optimizes away whole loop, as assigned values are never used, or replaces array with some precalculated values, so that loop isn't even executed and you get 0 milliseconds.

Having changed 1 to `i*j`, `i` get the same timings for both vector and array, unless pass `-O1` flag to gcc, then in both cases I get 0 milliseconds.

So, first of all, double-check whether your loops are **actually** executed.
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...