/* #define and && #define not ! #define or || */ #include #include #include #include #include #include #include #include using namespace std; using namespace boost::sort; 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 distribution_01(0.0, 1.0); string heading; double t; timer timer_01; timer timer_02; heading = "Program starts"; t = timer_01.elapsed(); print_time(heading, t); // Size const int n1 = 1024 * 1024 ; const int n2 = 512 - 32 ; const int array_size = n1 * n2; int r; int nr; nr=array_size; // array x; vector x(array_size) ; for (r = 0; r < nr; r++) x[r] = distribution_01(engine_01); heading = "Random numbers"; t = timer_01.elapsed(); print_time(heading, t); timer_01.reset(); boost::sort::parallel_stable_sort( x.begin() , x.end() ); heading = "Boost sort"; t = timer_01.elapsed(); print_time(heading, t); heading = "Total time"; t = timer_02.elapsed(); print_time(heading, t); return(0); }