-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (82 loc) · 2.81 KB
/
main.cpp
File metadata and controls
95 lines (82 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include "mergesort.h"
#include "heapsort.h"
#include "quicksort.h"
#include <chrono>
#include <algorithm>
#include <chrono>
#include <cassert>
#include <random>
#include "insertion.h"
#include "hybrid.h"
constexpr int step = 100; //100
constexpr int maxlen = 10000; //500 /*10000;*/
constexpr int times = 100;
/* constexpr int step = 10; */
/* constexpr int maxlen = 100; */
/* constexpr int times = 10; */
using std::chrono::nanoseconds;
int main() {
std::random_device rd;
std::mt19937 gen(rd());
std::ofstream file("output10000hybridfinal.txt");
for (int len = step ; len <= maxlen ; len += step) {
nanoseconds he(0);
nanoseconds merge(0);
nanoseconds quick(0);
nanoseconds insert(0);
nanoseconds hybrid(0);
std::vector<int>original(len);
for (int i = 0 ; i < len ; i++) {
original[i] = i;
}
std::vector<int>arr;
std::vector<int>sorted;
for (int t = 0 ; t < times ; t++) {
std::shuffle(original.begin(), original.end(), gen);//randomly sorted array
{
arr = original;
auto begin = std::chrono::steady_clock::now();
heapSort(arr);
auto end = std::chrono::steady_clock::now();
nanoseconds total(end - begin);
he += total;
}
{
arr = original;
auto begin = std::chrono::steady_clock::now();
quickSort(arr,0,arr.size()-1); //its either size or size-1 depends
auto end = std::chrono::steady_clock::now();
nanoseconds total(end - begin);
quick += total;
}
{
arr = original;
auto begin = std::chrono::steady_clock::now();
mergesort(arr);
auto end = std::chrono::steady_clock::now();
nanoseconds total(end - begin);
merge += total;
}
{
arr = original;
auto begin = std::chrono::steady_clock::now();
insert_sort(arr);
auto end = std::chrono::steady_clock::now();
nanoseconds total(end - begin);
insert += total;
}
{
arr = original;
auto begin = std::chrono::steady_clock::now();
hybridSort(arr,0,arr.size()-1);
auto end = std::chrono::steady_clock::now();
nanoseconds total(end - begin);
hybrid += total;
}
}
file << len << " "<< he.count() / times << " "<< merge.count() / times << " "<< insert.count() / times << " "<< quick.count() / times << " " << hybrid.count() / times << std::endl;
}
file.close();
return 0;
}