benchmark/radix_sort-bench.cc
author alpar
Thu, 02 Feb 2006 17:43:24 +0000
changeset 1946 17eb3eaad9f8
child 1956 a055123339d5
permissions -rw-r--r--
- workaround for a Doxygen 1.4.6 bug
- other doc fixes
     1 #define NDEBUG
     2 
     3 #include <lemon/time_measure.h>
     4 #include <lemon/smart_graph.h>
     5 #include <lemon/graph_utils.h>
     6 #include <lemon/maps.h>
     7 #include <lemon/error.h>
     8 
     9 #include <lemon/radix_sort.h>
    10 
    11 #include <vector>
    12 #include <algorithm>
    13 #include <cmath>
    14 
    15 using namespace std;
    16 using namespace lemon;
    17 
    18 void testRadixSort() {
    19   int n = 10000000;
    20   vector<int> data(n);
    21   for (int i = 0; i < n; ++i) {
    22     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    23   }
    24   radixSort(data.begin(), data.end());
    25 }
    26 
    27 
    28 void testCounterSort() {
    29   int n = 10000000;
    30   vector<int> data(n);
    31   for (int i = 0; i < n; ++i) {
    32     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    33   }
    34   counterSort(data.begin(), data.end());
    35 }
    36 
    37 void testSort() {
    38   int n = 10000000;
    39   vector<int> data(n);
    40   for (int i = 0; i < n; ++i) {
    41     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    42   }
    43   sort(data.begin(), data.end());
    44 }
    45 
    46 void testStableSort() {
    47   int n = 10000000;
    48   vector<int> data(n);
    49   for (int i = 0; i < n; ++i) {
    50     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    51   }
    52   stable_sort(data.begin(), data.end());
    53 }
    54 
    55 void testSorts() {
    56   {
    57     int n = 10000000;
    58     vector<int> data(n);
    59   }
    60   cout << "Radix sort: " << runningTimeTest(testRadixSort, 60) << endl;
    61   cout << "Counter sort: " << runningTimeTest(testCounterSort, 60) << endl;
    62   cout << "Standard sort: " << runningTimeTest(testSort, 60) << endl;
    63   cout << "Stable sort: " << runningTimeTest(testStableSort, 60) << endl;
    64 }
    65 
    66 
    67 int main() {
    68   testSorts();
    69   return 0;
    70 }