Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // Benchmark
  4. //
  5. // Created by Guilherme Avila on 05/02/17.
  6. // Copyright © 2017 guilhermebav. All rights reserved.
  7. //
  8. #include <hayai.hpp>
  9. #include <iostream>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <limits>
  13. #include "sorts.hpp"
  14.  
  15. using namespace std;
  16.  
  17. //const unsigned maxv = numeric_limits<unsigned int>::max();
  18. const unsigned maxv = 500000;
  19. const int test = 20;
  20. const int runs = 1000;
  21. const int size = 200000;
  22.  
  23. vector<vector<unsigned>> d(runs, vector<unsigned>(size));
  24. vector<unsigned> v(size);
  25. int i=0;
  26.  
  27. //int main(int argc, const char * argv[]) {
  28. // srand((unsigned)time(NULL));
  29. // vector<unsigned> z;
  30. // for (int i=0; i < test; i++){
  31. // int b = (2*rand()) % maxv + 1;
  32. // z.push_back(b);
  33. // }
  34. // for (int i=0; i < test; i++){
  35. // cout << z[i] << " ";
  36. // }
  37. // cout << endl;
  38. // c_radix_sort(z.begin(), z.end());
  39. // cout << endl;
  40. // for (int i=0; i < test; i++){
  41. // cout << z[i] << " ";
  42. // }
  43. // cout << endl;
  44. // return 0;
  45. //}
  46.  
  47. int main(int argc, const char * argv[]) {
  48. srand((unsigned)time(NULL));
  49. for(int i=0;i<runs;i++) {
  50. for(int j=0;j<size;j++){
  51. int b = (2*rand()) % maxv + 1;
  52. d[i][j] = b;
  53. }
  54. }
  55. i=0;
  56. hayai::ConsoleOutputter consoleOutputter;
  57. hayai::Benchmarker::AddOutputter(consoleOutputter);
  58. hayai::Benchmarker::RunAllTests();
  59. return 0;
  60. }
  61.  
  62. bool myfunction (int i,int j) { return (i<j); }
  63.  
  64. class Sorts : public ::hayai::Fixture {
  65. public:
  66. virtual void SetUp() {
  67. v.assign(d[i].begin(),d[i].end());
  68. // sort(v.begin(), v.end());
  69. // reverse(v.begin(),v.end());
  70. }
  71.  
  72. virtual void TearDown() {
  73. i++;
  74. if(i==runs) i=0;
  75. }
  76. };
  77.  
  78. //BENCHMARK_F(Sorts, merge_sort, runs, 1) {
  79. // merge_sort(v.begin(), v.end());
  80. //}
  81. //
  82. //BENCHMARK_F(Sorts, c_merge_sort, runs, 1) {
  83. // c_merge_sort(v.begin(), v.end());
  84. //}
  85. //
  86. //BENCHMARK_F(Sorts, quick_sort, runs, 1) {
  87. // quick_sort(v.begin(), v.end());
  88. //}
  89. //
  90. //BENCHMARK_F(Sorts, tim_sort, runs, 1) {
  91. // tim_sort(v.begin(), v.end());
  92. //}
  93.  
  94. BENCHMARK_F(Sorts, radix_sort, runs, 1) {
  95. radix_sort(v.begin(), v.end());
  96. }
  97.  
  98.  
  99. //BENCHMARK_F(Sorts, stl_sort, runs, 1) {
  100. // sort(v.begin(), v.end());
  101. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement