COIN-OR::LEMON - Graph Library

source: lemon-0.x/benchmark/radix_sort-bench.cc @ 1939:591e717155ac

Last change on this file since 1939:591e717155ac was 1833:6d107b0b6b46, checked in by Balazs Dezso, 18 years ago

Radix sort algorithm

File size: 1.5 KB
Line 
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
15using namespace std;
16using namespace lemon;
17
18void 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
28void 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
37void 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
46void 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
55void 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
67int main() {
68  testSorts();
69  return 0;
70}
Note: See TracBrowser for help on using the repository browser.