forked from litv8/testk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (37 loc) · 1.19 KB
/
main.cpp
File metadata and controls
45 lines (37 loc) · 1.19 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
#include <iostream>
#include <chrono>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
struct Result {
double generation_time;
double sorting_time;
std::string to_json() {
std::stringstream ss;
ss << "{"
<< "\"generation_time\":" << generation_time << ","
<< "\"sorting_time\":" << sorting_time
<< "}";
return ss.str();
}
};
int main() {
const size_t N = 50000;
std::vector<double> numbers(N);
Result result;
auto start_gen = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < N; ++i) {
numbers[i] = N - i;
}
auto end_gen = std::chrono::high_resolution_clock::now();
result.generation_time = std::chrono::duration<double, std::milli>(end_gen - start_gen).count();
auto start_sort = std::chrono::high_resolution_clock::now();
std::sort(numbers.begin(), numbers.end());
auto end_sort = std::chrono::high_resolution_clock::now();
result.sorting_time = std::chrono::duration<double, std::milli>(end_sort - start_sort).count();
std::ofstream out("result.json");
out << result.to_json();
out.close();
return 0;
}