/* Lecture Code 5.7 * * Time trial of vector vs deque for element access. However, this time the container is declared inside * the outer loop, which has a major performance hit for the deque. * Refer to 5.2 or 5.3 for more info on tricky syntax. */ #include #include #include #include using namespace std; const int NUM_ELEMS = 100000; const int NUM_TESTS = 1000; template void RunTest() { clock_t start = clock(); for(int h = 0; h < NUM_TESTS; h++) { ContainerType myContainer(NUM_ELEMS); for(int i = 0; i < NUM_ELEMS; i++) myContainer[i] = i; } start = clock() - start; cout << "Test completed in "; cout << ((double)(start) / CLOCKS_PER_SEC); cout << " seconds." << endl; } int main() { RunTest >(); RunTest >(); return 0; }