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
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.