benchmark/radix_sort-bench.cc
changeset 2242 16523135943d
parent 1956 a055123339d5
child 2391 14a343be7a5a
equal deleted inserted replaced
1:4cd4778f4d34 2:73d9843fe5bf
    24 #include <lemon/maps.h>
    24 #include <lemon/maps.h>
    25 #include <lemon/error.h>
    25 #include <lemon/error.h>
    26 
    26 
    27 #include <lemon/radix_sort.h>
    27 #include <lemon/radix_sort.h>
    28 
    28 
       
    29 #include <lemon/random.h>
       
    30 
    29 #include <vector>
    31 #include <vector>
    30 #include <algorithm>
    32 #include <algorithm>
    31 #include <cmath>
    33 #include <cmath>
    32 
    34 
    33 using namespace std;
    35 using namespace std;
    35 
    37 
    36 void testRadixSort() {
    38 void testRadixSort() {
    37   int n = 10000000;
    39   int n = 10000000;
    38   vector<int> data(n);
    40   vector<int> data(n);
    39   for (int i = 0; i < n; ++i) {
    41   for (int i = 0; i < n; ++i) {
    40     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    42     data[i] = rnd[1000] - 500;
    41   }
    43   }
    42   radixSort(data.begin(), data.end());
    44   radixSort(data.begin(), data.end());
    43 }
    45 }
    44 
    46 
    45 
    47 
    46 void testCounterSort() {
    48 void testCounterSort() {
    47   int n = 10000000;
    49   int n = 10000000;
    48   vector<int> data(n);
    50   vector<int> data(n);
    49   for (int i = 0; i < n; ++i) {
    51   for (int i = 0; i < n; ++i) {
    50     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    52     data[i] = rnd[1000] - 500;
    51   }
    53   }
    52   counterSort(data.begin(), data.end());
    54   counterSort(data.begin(), data.end());
    53 }
    55 }
    54 
    56 
    55 void testSort() {
    57 void testSort() {
    56   int n = 10000000;
    58   int n = 10000000;
    57   vector<int> data(n);
    59   vector<int> data(n);
    58   for (int i = 0; i < n; ++i) {
    60   for (int i = 0; i < n; ++i) {
    59     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    61     data[i] = rnd[1000] - 500;
    60   }
    62   }
    61   sort(data.begin(), data.end());
    63   sort(data.begin(), data.end());
    62 }
    64 }
    63 
    65 
    64 void testStableSort() {
    66 void testStableSort() {
    65   int n = 10000000;
    67   int n = 10000000;
    66   vector<int> data(n);
    68   vector<int> data(n);
    67   for (int i = 0; i < n; ++i) {
    69   for (int i = 0; i < n; ++i) {
    68     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    70     data[i] = rnd[1000] - 500;
    69   }
    71   }
    70   stable_sort(data.begin(), data.end());
    72   stable_sort(data.begin(), data.end());
    71 }
    73 }
    72 
    74 
    73 void testSorts() {
    75 void testSorts() {