benchmark/radix_sort-bench.cc
author deba
Wed, 06 Sep 2006 10:10:48 +0000
changeset 2201 597714206430
parent 1833 6d107b0b6b46
child 2242 16523135943d
permissions -rw-r--r--
Bug fix in DescriptorMap
Avoiding the possibility of the memory leak
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #define NDEBUG
    20 
    21 #include <lemon/time_measure.h>
    22 #include <lemon/smart_graph.h>
    23 #include <lemon/graph_utils.h>
    24 #include <lemon/maps.h>
    25 #include <lemon/error.h>
    26 
    27 #include <lemon/radix_sort.h>
    28 
    29 #include <vector>
    30 #include <algorithm>
    31 #include <cmath>
    32 
    33 using namespace std;
    34 using namespace lemon;
    35 
    36 void testRadixSort() {
    37   int n = 10000000;
    38   vector<int> data(n);
    39   for (int i = 0; i < n; ++i) {
    40     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    41   }
    42   radixSort(data.begin(), data.end());
    43 }
    44 
    45 
    46 void testCounterSort() {
    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   counterSort(data.begin(), data.end());
    53 }
    54 
    55 void testSort() {
    56   int n = 10000000;
    57   vector<int> data(n);
    58   for (int i = 0; i < n; ++i) {
    59     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    60   }
    61   sort(data.begin(), data.end());
    62 }
    63 
    64 void testStableSort() {
    65   int n = 10000000;
    66   vector<int> data(n);
    67   for (int i = 0; i < n; ++i) {
    68     data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
    69   }
    70   stable_sort(data.begin(), data.end());
    71 }
    72 
    73 void testSorts() {
    74   {
    75     int n = 10000000;
    76     vector<int> data(n);
    77   }
    78   cout << "Radix sort: " << runningTimeTest(testRadixSort, 60) << endl;
    79   cout << "Counter sort: " << runningTimeTest(testCounterSort, 60) << endl;
    80   cout << "Standard sort: " << runningTimeTest(testSort, 60) << endl;
    81   cout << "Stable sort: " << runningTimeTest(testStableSort, 60) << endl;
    82 }
    83 
    84 
    85 int main() {
    86   testSorts();
    87   return 0;
    88 }