Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <algorithm>
- #include <chrono>
- using namespace std;
- class timer{
- std::chrono::time_point<std::chrono::high_resolution_clock> a,b;
- public:
- void start(){a = std::chrono::high_resolution_clock::now();}
- void stop() {b = std::chrono::high_resolution_clock::now();}
- double value()
- {
- std::chrono::duration<double> elapsed_seconds = b-a;
- return elapsed_seconds.count();
- }
- };
- int main()
- {
- const size_t N = 120'000'000;
- vector<uint64_t> tab;
- random_device rd;
- mt19937_64 gen(rd());
- uniform_int_distribution<uint64_t> dist(0);
- for (int i=0; i<5; i++){
- generate_n(back_inserter(tab), N, [&](){ return dist(gen) ; } ) ;
- timer st;
- st.start();
- sort(begin(tab),end(tab));
- st.stop();
- cout<<tab[3]<<endl; //do not optimize the array out, please
- cout<<is_sorted(begin(tab),end(tab))<<endl;
- cout<<st.value()*1000<<" ms"<<endl;
- tab.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement