// z6.1-vector-insert-tictoc.cc // #include #include #include "tictoc.h" using namespace std; int main() { vector tempValues; // Dummy vector to demo vector ops int vectorSize; // User defined size int numOps; // Number of operations to perform int i; // Loop index cout << "Enter initial vector size: "; cin >> vectorSize; cout << "Enter number of operations: "; cin >> numOps; cout << "\nvectorSize = " << vectorSize << ", numOps = " << numOps << endl; cout << " Resizing vector..." << flush; tictoc tt; tempValues.resize(vectorSize); tt.toc(); cout << "done: " << tt.CPU << " seconds." << endl; cout << " Writing to each element..." << flush; tt.tic(); for (i = 0; i < vectorSize; ++i) { tempValues.at(i) = 777; // Any value } tt.toc(); cout << "done: " << tt.CPU << " seconds." << endl; cout << " Doing " << numOps << " pushbacks..." << flush; tt.tic(); for (i = 0; i < numOps; ++i) { tempValues.push_back(888); // Any value } tt.toc(); cout << "done: " << tt.CPU << " seconds." << endl; cout << " Doing " << numOps << " inserts..." << flush; tt.tic(); for (i = 0; i < numOps; ++i) { tempValues.insert(tempValues.begin() + 0, 444); } tt.toc(); cout << "done: " << tt.CPU << " seconds." << endl; cout << " Doing " << numOps << " erases..." << flush; tt.tic(); for (i = 0; i < numOps; ++i) { tempValues.erase(tempValues.begin() + 0); } tt.toc(); cout << "done: " << tt.CPU << " seconds." << endl; return 0; }