#include using namespace std; class timer { private: typedef std::chrono::high_resolution_clock hi_res_clock; typedef std::chrono::duration > second_; std::chrono::time_point start_time ; public: timer() : start_time(hi_res_clock::now()) {} void reset() { start_time = hi_res_clock::now(); } double elapsed() const { double t ; t = std::chrono::duration_cast ( hi_res_clock::now() - start_time ).count() ; return(t) ; } }; #include #include #include #include #include using namespace std; void print_time(const string & heading , const double & t) { cout << heading << " : " ; cout.setf(ios::right); cout.setf(ios::showpoint); cout.setf(ios::fixed); cout.width(10); cout.precision(6); cout << t << endl; } int main() { string heading; int n=1000000; int i; int j; int * x; double t; timer timer_01; timer timer_02; heading = "Program starts"; t=timer_01.elapsed(); print_time( heading , t); timer_01.reset(); cout << "\n"; heading = " Allocation and assign "; for (i=1;i<4;i++) { cout.width(10); cout << n ; x = new int[n]; if ( x == NULL) { cout << "Allocation failed" << endl; exit(1); } for (j=0;j