#include #include #include #include #include #include #include #include #include #include using namespace std; class timer { public: timer() : start_timing(hi_res_clock::now()) {} void reset() { start_timing = hi_res_clock::now(); } double elapsed() const { return(std::chrono::duration_cast (hi_res_clock::now() - start_timing).count()); } private: typedef std::chrono::high_resolution_clock hi_res_clock; typedef std::chrono::duration > second_; std::chrono::time_point start_timing; }; void print_time(const string & heading , const double & t) { // Right justifies to column 30 const int nb=30; int n; int i; int l; l = heading.length(); if ( l >= nb ) cout << " Warning heading too long. Reduce to less than 30 characters" << endl; n=nb-l; cout << heading ; for (i=1;i input_list; heading = "Program starts"; t=timer_01.elapsed(); print_time( heading , t); for (;;) { input_file >> temp; if (input_file.eof()) break; input_list.push_back( temp ); n++; } cout << "End of file reached" << endl; cout << n << " items read " << endl; input_file.close(); heading="List created"; t=timer_01.elapsed(); print_time(heading , t); timer_01.reset(); heading = "Copy to vector"; vector x(n); int i=0; list::iterator it; for (it=input_list.begin(); it != input_list.end(); ++it) { x[i]=*it; i++; } t=timer_01.elapsed(); print_time(heading , t); cout << x[0] << " " << x[n-1] << endl; t=timer_02.elapsed(); heading = "Total time"; print_time(heading , t); return(0); }