Created
August 4, 2012 10:40
-
-
Save motonacciu/3256629 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::vector<int> v(N); | |
| // Initialize the array with random elements between 0 and 100 | |
| for_each(v.begin(), v.end(), [](int& cur){ cur = rand()%100; }); | |
| auto print_vec = [](std::ostream& out, const std::vector<int>& vec) { | |
| std:copy(v.begin(), v.end(), std::ostream_iterator<int>(out, ", ")); | |
| out << std::endl | |
| }; | |
| // print out the unordered array | |
| print_vec(std::cout, v); | |
| std::vector<int> a; | |
| double tot_time=0; | |
| for(int i=0; i<ITER; i++) { | |
| a = v; | |
| auto start = std::chrono::system_clock::now(); | |
| /*********************** | |
| * Call sorting method | |
| **********************/ | |
| tot_time += std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now()-start).count(); | |
| } | |
| // Print the sorted vector | |
| print_vec(std::cout, a); | |
| std::cout << "Vector ordered in " << tot_time/ITER << " nano-secs" << std::endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment