Skip to content

Instantly share code, notes, and snippets.

@motonacciu
Created August 4, 2012 10:40
Show Gist options
  • Select an option

  • Save motonacciu/3256629 to your computer and use it in GitHub Desktop.

Select an option

Save motonacciu/3256629 to your computer and use it in GitHub Desktop.
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