//: C07:IndexingVsAt.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // Comparing "at()" to operator[]. #include #include #include #include #include "../require.h" using namespace std; int main(int argc, char* argv[]) { long count = 1000; int sz = 1000; if(argc >= 2) count = atoi(argv[1]); if(argc >= 3) sz = atoi(argv[2]); vector vi(sz); clock_t ticks = clock(); for(int i1 = 0; i1 < count; i1++) for(int j = 0; j < sz; j++) vi[j]; cout << "vector[] " << clock() - ticks << endl; ticks = clock(); for(int i2 = 0; i2 < count; i2++) for(int j = 0; j < sz; j++) vi.at(j); cout << "vector::at() " << clock()-ticks < di(sz); ticks = clock(); for(int i3 = 0; i3 < count; i3++) for(int j = 0; j < sz; j++) di[j]; cout << "deque[] " << clock() - ticks << endl; ticks = clock(); for(int i4 = 0; i4 < count; i4++) for(int j = 0; j < sz; j++) di.at(j); cout << "deque::at() " << clock()-ticks <