// CPPList.cpp - By Michael G. Workman // // Example C++ console application to time the building and display of a list // and compare to C# and Java Programming Languages // // This example application freely distributable under terms of MIT open source license #include #include #include using namespace std; int main() { // declare list of integers list intList; // loop through adding 100 thousand integers to the list // then display the contents of the list // and then time the total amount of time to complete clock_t start = clock(); for (int i = 0; i < 100000; i++) { intList.push_back(i); } // iterate through list and display each item for (list::iterator it = intList.begin(); it != intList.end(); it++) { cout << (*it) << endl; } clock_t end = clock(); // calculate time in seconds double timeSeconds = ((double) end - start) / (double) CLOCKS_PER_SEC; // output the results cout.precision(10); cout << "C++ time to build and display list: " << timeSeconds << " seconds" << endl; cout << "Number of elements: " << intList.size() << endl; return 0; }