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