Advertisement
S1xe

S1xe

Apr 24th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. #include <chrono>
  5. #include <random>
  6. using namespace std;
  7. int main()
  8. {
  9. vector<int> v(10000000,0);
  10. int n{0};
  11. //依次生成0-9999999
  12. generate(v.begin(), v.end(), [&] {return n++; });
  13.  
  14. //根据mt19937将v乱序
  15. random_device rd;
  16. mt19937 g(rd());
  17. auto start = chrono::system_clock::now();//计时开始
  18. shuffle(v.begin(), v.end(),g);
  19. auto end = chrono::system_clock::now();//计时结束
  20.  
  21. //输出计时
  22. auto duration = chrono::duration_cast<chrono::microseconds>(end - start);
  23. cout << double(duration.count()) * chrono::microseconds::period::num / chrono::microseconds::period::den << endl;
  24.  
  25. cout << v[v.size() - 1] << endl;//可有可无
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement