Last active
October 23, 2016 18:58
-
-
Save illescasDaniel/9973f780d9a0d7c647a9e959f94b5bb1 to your computer and use it in GitHub Desktop.
Generate random numbers and sort it [C++]
This file contains 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
#include <iostream> | |
#include <chrono> | |
#include <vector> | |
#include <random> | |
using namespace std; | |
using namespace chrono; | |
int main() { | |
constexpr size_t size = 10000000; | |
random_device rd; | |
mt19937_64 g(rd()); | |
vector<uint> numbers(size); | |
for_each(numbers.begin(), numbers.end(), [&](uint& number){ number = g(); }); | |
cout << "starting" << endl; | |
auto t1 = high_resolution_clock::now(); | |
sort(numbers.begin(), numbers.end()); | |
auto t2 = high_resolution_clock::now(); | |
cout << float(duration_cast<milliseconds>(t2 - t1).count()) / float(1000) << "s" << endl; | |
// Display sorted values: | |
// for (auto value: numbers) { | |
// cout << value << ' '; | |
// } | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment