-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeasureTimeExecuted.cpp
More file actions
executable file
·43 lines (34 loc) · 1.42 KB
/
Copy pathmeasureTimeExecuted.cpp
File metadata and controls
executable file
·43 lines (34 loc) · 1.42 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
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
typedef high_resolution_clock Clock;
typedef Clock::time_point ClockTime;
void printExecutionTime(ClockTime start_time, ClockTime end_time);
int main()
{
ClockTime start_time = Clock::now();
//Put the function here
ClockTime end_time = Clock::now();
printExecutionTime(start_time, end_time);
return 0;
}
void printExecutionTime(ClockTime start_time, ClockTime end_time)
{
auto execution_time_ns = duration_cast<nanoseconds>(end_time - start_time).count();
auto execution_time_ms = duration_cast<microseconds>(end_time - start_time).count();
auto execution_time_sec = duration_cast<seconds>(end_time - start_time).count();
auto execution_time_min = duration_cast<minutes>(end_time - start_time).count();
auto execution_time_hour = duration_cast<hours>(end_time - start_time).count();
cout << "\nExecution Time: ";
if (execution_time_hour > 0)
cout << "" << execution_time_hour << " Hours, ";
if (execution_time_min > 0)
cout << "" << execution_time_min % 60 << " Minutes, ";
if (execution_time_sec > 0)
cout << "" << execution_time_sec % 60 << " Seconds, ";
if (execution_time_ms > 0)
cout << "" << execution_time_ms % long(1E+3) << " MicroSeconds, ";
if (execution_time_ns > 0)
cout << "" << execution_time_ns % long(1E+6) << " NanoSeconds, ";
}