My Find function is very simple, it is as below.
IntVector iv; //global vector variable.
int Find(int elementToFind)
int index = 0;
for (IntVector::const_iterator it = iv.begin(); itr < iv.end(); ++itr)
if (*itr == elementToFind)
index = itr - iv.begin();
As explained before, vector iv contains 10Lacselements (i.e. from 1- 10Lacs). Now, I am trying to find the index of element 5,00,000 and 9,99,999. I am measuring the time taken by Find() function to return the index of these values.
And I am getting3 - 4times slower performance. Time is being measured using tick_count variable.
The figures are as below. time (in sec)
On 32-bit machine On 64-bit machine
Time to find index of middle element 0.0052690.0192848
i.e. value 5,00,000
Time to find index of last but one element0.010935 0.0407119
i.e. value 9,99,999
The results for vector withcache_aligned_allocator are 3 - 8 times slower.