#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) { // max heading length of 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 thann 30 characters" << endl; n=nb-l; cout << heading ; for (i=1;i x1 ; array x2 ; double t; timer timer_01; timer timer_02; heading = "Program starts"; t=timer_01.elapsed(); print_time( heading , t); x1.fill(1); heading = "Initialise using fill()"; t=timer_01.elapsed(); print_time(heading , t); timer_01.reset(); x2=x1; heading = "Array assignment x2=x1"; t=timer_01.elapsed(); print_time(heading , t); timer_01.reset(); heading = "if x1=x2 test"; if ( x1==x2 ) cout << " Arrays are equal" << endl; t=timer_01.elapsed(); print_time(heading , t); timer_01.reset(); t=timer_02.elapsed(); heading = "Total time"; print_time(heading , t); return(0); }