I just want to know which one is best (vector
or list
) on performance
basis?
To understand that just wrote a simple tester to calculate the time for
vector
s and list
s...
Vector code :
1. started the timer
2. pushing 3000 elements in to to the vector
3. using iterator to access all the elements from the container and
printing it
4. stoped the timer
5. running the vector code, getting the output as 0ms.
List code:
1. start the timer
2. pushing 3000 elements into the list
3. using iterator to access all the elements from the container and
printing it
4. stop the timer
5. running the list code,getting the output as 10ms.
But few of my friends are saying that `list` is best.....Can someone tell me
the exact difference between this two and which one is best among these?
Test code:
int main() {
int i;
vector<int> vec;
vector<int>::iterator vIter;
clock_t tstart = 0, tstop = 0;
tstart = clock();
for (i = 0; i < 3000; i++) vec.push_back(i);
for (vIter = vec.begin(); vIter != vec.end(); vIter++) cout << *vIter << endl;
tstop = clock();
std::cout << mstimer(tstart, tstop) << " (ms)" << std::endl;
return 0;
}