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@2553
|
5 |
* Copyright (C) 2003-2008
|
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@2242
|
29 |
#include <lemon/random.h>
|
deba@2242
|
30 |
|
deba@1833
|
31 |
#include <vector>
|
deba@1833
|
32 |
#include <algorithm>
|
deba@1833
|
33 |
#include <cmath>
|
deba@1833
|
34 |
|
deba@1833
|
35 |
using namespace std;
|
deba@1833
|
36 |
using namespace lemon;
|
deba@1833
|
37 |
|
deba@1833
|
38 |
void testRadixSort() {
|
deba@1833
|
39 |
int n = 10000000;
|
deba@1833
|
40 |
vector<int> data(n);
|
deba@1833
|
41 |
for (int i = 0; i < n; ++i) {
|
deba@2242
|
42 |
data[i] = rnd[1000] - 500;
|
deba@1833
|
43 |
}
|
deba@1833
|
44 |
radixSort(data.begin(), data.end());
|
deba@1833
|
45 |
}
|
deba@1833
|
46 |
|
deba@1833
|
47 |
|
deba@1833
|
48 |
void testCounterSort() {
|
deba@1833
|
49 |
int n = 10000000;
|
deba@1833
|
50 |
vector<int> data(n);
|
deba@1833
|
51 |
for (int i = 0; i < n; ++i) {
|
deba@2242
|
52 |
data[i] = rnd[1000] - 500;
|
deba@1833
|
53 |
}
|
deba@1833
|
54 |
counterSort(data.begin(), data.end());
|
deba@1833
|
55 |
}
|
deba@1833
|
56 |
|
deba@1833
|
57 |
void testSort() {
|
deba@1833
|
58 |
int n = 10000000;
|
deba@1833
|
59 |
vector<int> data(n);
|
deba@1833
|
60 |
for (int i = 0; i < n; ++i) {
|
deba@2242
|
61 |
data[i] = rnd[1000] - 500;
|
deba@1833
|
62 |
}
|
deba@1833
|
63 |
sort(data.begin(), data.end());
|
deba@1833
|
64 |
}
|
deba@1833
|
65 |
|
deba@1833
|
66 |
void testStableSort() {
|
deba@1833
|
67 |
int n = 10000000;
|
deba@1833
|
68 |
vector<int> data(n);
|
deba@1833
|
69 |
for (int i = 0; i < n; ++i) {
|
deba@2242
|
70 |
data[i] = rnd[1000] - 500;
|
deba@1833
|
71 |
}
|
deba@1833
|
72 |
stable_sort(data.begin(), data.end());
|
deba@1833
|
73 |
}
|
deba@1833
|
74 |
|
deba@1833
|
75 |
void testSorts() {
|
deba@1833
|
76 |
{
|
deba@1833
|
77 |
int n = 10000000;
|
deba@1833
|
78 |
vector<int> data(n);
|
deba@1833
|
79 |
}
|
deba@1833
|
80 |
cout << "Radix sort: " << runningTimeTest(testRadixSort, 60) << endl;
|
deba@1833
|
81 |
cout << "Counter sort: " << runningTimeTest(testCounterSort, 60) << endl;
|
deba@1833
|
82 |
cout << "Standard sort: " << runningTimeTest(testSort, 60) << endl;
|
deba@1833
|
83 |
cout << "Stable sort: " << runningTimeTest(testStableSort, 60) << endl;
|
deba@1833
|
84 |
}
|
deba@1833
|
85 |
|
deba@1833
|
86 |
|
deba@1833
|
87 |
int main() {
|
deba@1833
|
88 |
testSorts();
|
deba@1833
|
89 |
return 0;
|
deba@1833
|
90 |
}
|