-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
81 lines (62 loc) · 2.12 KB
/
Copy pathbenchmark.cpp
File metadata and controls
81 lines (62 loc) · 2.12 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
#include <chrono>
#include <iostream>
#include "sort.hpp"
std::vector<int> unsorted;
std::vector<int> input;
std::vector<int> output;
namespace Benchmark {
using std::chrono::high_resolution_clock;
void displayTime(std::string title,std::chrono::_V2::system_clock::time_point t1,std::chrono::_V2::system_clock::time_point t2){
using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
duration<double, std::milli> ms_double = t2 - t1;
std::cout << title << ":\t";
std::cout << ms_double.count() << " ms\n";
}
void timeQuickSort() {
input = unsorted;
auto t1 = high_resolution_clock::now();
quickSort(input);
auto t2 = high_resolution_clock::now();
displayTime("quick", t1, t2);
}
void timeInsertionSort() {
input = unsorted;
auto t1 = high_resolution_clock::now();
insertionSort(input);
auto t2 = high_resolution_clock::now();
displayTime("insertion", t1, t2);
}
void timeSelectionSort(){
input = unsorted;
auto t1 = high_resolution_clock::now();
selectionSort(input);
auto t2 = high_resolution_clock::now();
displayTime("selection", t1, t2);
}
void timeBubbleSort(){
input = unsorted;
auto t1 = high_resolution_clock::now();
bubbleSort(input);
auto t2 = high_resolution_clock::now();
displayTime("bubble", t1, t2);
}
void timeMergeSort(){
input = unsorted;
auto t1 = high_resolution_clock::now();
mergeSort(input,0,input.size()-1);
auto t2 = high_resolution_clock::now();
displayTime("merge", t1, t2);
}
}
int main() {
readFromFile("testCases/randomNumbers1.txt", unsorted);
readFromFile("testCases/randomNumbers1-out.txt", output);
Benchmark::timeQuickSort();
Benchmark::timeInsertionSort();
Benchmark::timeBubbleSort();
Benchmark::timeSelectionSort();
Benchmark::timeMergeSort();
return 0;
}