This repository was archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_measurements.cpp
More file actions
68 lines (48 loc) · 1.67 KB
/
time_measurements.cpp
File metadata and controls
68 lines (48 loc) · 1.67 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
#include "time_measurements.h"
time_measurements::time_measurements()
{
}
int time_measurements::exec(std::string algorithm) {
algorithm = "std_sort";
loop_run_algorithm<std_sort>(algorithm);
algorithm = "median_quick_sort";
loop_run_algorithm<median_quick_sort>(algorithm);
algorithm = "right_elem_quick_sort";
loop_run_algorithm<right_elem_quick_sort>(algorithm);
algorithm = "fast_quick_sort";
loop_run_algorithm<fast_quick_sort>(algorithm);
algorithm = "right_elem_quick_sort_own";
loop_run_algorithm<right_elem_quick_sort_own>(algorithm);
algorithm = "selection_sort";
loop_run_algorithm<selection_sort>(algorithm);
algorithm = "insertion_sort";
loop_run_algorithm<insertion_sort>(algorithm);
int stop;
std::cin >> stop;
return 0;
}
// https://www.programiz.com/cpp-programming/examples/standard-deviation
double time_measurements::deviation_function(std::string algorithm) {
double tot_time = 0;
double std_dev = 0;
for (auto e : deviation_vec[algorithm]) {
tot_time+=e.time;
}
auto n = deviation_vec[algorithm].size();
auto avg = tot_time / n;
for (auto e : deviation_vec[algorithm]) {
std_dev += pow(e.time - avg, 2);
}
return sqrt(std_dev / n);
}
void time_measurements::print(std::string algorithm)
{
/// lägger till i felsökningslistan
std::cout << "Algorithm: " << algorithm
<< ", Runs: " <<runs
<<", Numbers: " << deviation_vec[algorithm].front().amount
<< ", Time: " << deviation_vec[algorithm].front().time<< " seconds, "
<< "Deviation: " << deviation_function(algorithm) << ", ";
is_sorted ()(std::begin(vec), std::end(vec));
std::cout << std::endl;
}