COIN-OR::LEMON - Graph Library

source: lemon-0.x/benchmark/radix_sort-bench.cc @ 1971:9a59a6cacfd9

Last change on this file since 1971:9a59a6cacfd9 was 1956:a055123339d5, checked in by Alpar Juttner, 18 years ago

Unified copyright notices

File size: 2.1 KB
Line 
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
33using namespace std;
34using namespace lemon;
35
36void 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
46void 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
55void 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
64void 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
73void 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
85int main() {
86  testSorts();
87  return 0;
88}
Note: See TracBrowser for help on using the repository browser.