1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/benchmark/radix_sort-bench.cc Mon Nov 28 11:14:01 2005 +0000
1.3 @@ -0,0 +1,70 @@
1.4 +#define NDEBUG
1.5 +
1.6 +#include <lemon/time_measure.h>
1.7 +#include <lemon/smart_graph.h>
1.8 +#include <lemon/graph_utils.h>
1.9 +#include <lemon/maps.h>
1.10 +#include <lemon/error.h>
1.11 +
1.12 +#include <lemon/radix_sort.h>
1.13 +
1.14 +#include <vector>
1.15 +#include <algorithm>
1.16 +#include <cmath>
1.17 +
1.18 +using namespace std;
1.19 +using namespace lemon;
1.20 +
1.21 +void testRadixSort() {
1.22 + int n = 10000000;
1.23 + vector<int> data(n);
1.24 + for (int i = 0; i < n; ++i) {
1.25 + data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
1.26 + }
1.27 + radixSort(data.begin(), data.end());
1.28 +}
1.29 +
1.30 +
1.31 +void testCounterSort() {
1.32 + int n = 10000000;
1.33 + vector<int> data(n);
1.34 + for (int i = 0; i < n; ++i) {
1.35 + data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
1.36 + }
1.37 + counterSort(data.begin(), data.end());
1.38 +}
1.39 +
1.40 +void testSort() {
1.41 + int n = 10000000;
1.42 + vector<int> data(n);
1.43 + for (int i = 0; i < n; ++i) {
1.44 + data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
1.45 + }
1.46 + sort(data.begin(), data.end());
1.47 +}
1.48 +
1.49 +void testStableSort() {
1.50 + int n = 10000000;
1.51 + vector<int> data(n);
1.52 + for (int i = 0; i < n; ++i) {
1.53 + data[i] = (int)(1000 * (rand() / (RAND_MAX + 1.0))) - 500;
1.54 + }
1.55 + stable_sort(data.begin(), data.end());
1.56 +}
1.57 +
1.58 +void testSorts() {
1.59 + {
1.60 + int n = 10000000;
1.61 + vector<int> data(n);
1.62 + }
1.63 + cout << "Radix sort: " << runningTimeTest(testRadixSort, 60) << endl;
1.64 + cout << "Counter sort: " << runningTimeTest(testCounterSort, 60) << endl;
1.65 + cout << "Standard sort: " << runningTimeTest(testSort, 60) << endl;
1.66 + cout << "Stable sort: " << runningTimeTest(testStableSort, 60) << endl;
1.67 +}
1.68 +
1.69 +
1.70 +int main() {
1.71 + testSorts();
1.72 + return 0;
1.73 +}