Monday, January 18, 2016

vector::operator [] is time consuming

I am handling large amount of data (4000*4000 double). I found vector::operator [] is really expensive in terms of CPU cost.

vector arr = AllocateArray(4000, 4000);
while( _all_elements_in_arr_)
{
  arr[i] = x; // it's extremely slow.
}

So avoid of using operator [], instead, use direct address of the buffer could improve the performance tremendously:

double * buffer_addr = &arr[0];

No comments: