Vector [] vs copying
- by sak
What is faster and/or generally better?
vector<myType> myVec;
int i;
myType current;
for( i = 0; i < 1000000; i ++ )
{
current = myVec[ i ];
doSomethingWith( current );
doAlotMoreWith( current );
messAroundWith( current );
checkSomeValuesOf( current );
}
or
vector<myType> myVec;
int i;
for( i = 0; i < 1000000; i ++ )
{
doSomethingWith( myVec[ i ] );
doAlotMoreWith( myVec[ i ] );
messAroundWith( myVec[ i ] );
checkSomeValuesOf( myVec[ i ] );
}
I'm currently using the first solution. There are really millions of calls per second and every single bit comparison/move is performance-problematic.