-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
83 lines (58 loc) · 1.34 KB
/
test.cpp
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
#include <iostream>
#include <chrono>
using namespace std;
using namespace std::chrono;
void function()
{
long long number = 0;
{
for( long long i = 0; i != 200; ++i )
{
number += 5;
}
}
}
int main()
{
high_resolution_clock::time_point t1 = high_resolution_clock::now();
function();
high_resolution_clock::time_point t2 = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>( t2 - t1 ).count();
cout << duration<<" microseconds";
return 0;
}
#include<time.h>
int main()
{
clock_t start_t, end_t,total_t;
start_t = clock();
g = prims(g);
end_t = clock();
total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC*1000;
cout<<"duration: "<<total_t<<" ms";
return 0;
}
#include<windows.h>
inline long long PerformanceCounter() noexcept
{
LARGE_INTEGER li;
::QueryPerformanceCounter(&li);
return li.QuadPart;
}
// -----------------------------------------
inline long long PerformanceFrequency() noexcept
{
LARGE_INTEGER li;
::QueryPerformanceFrequency(&li);
return li.QuadPart;
}
int main()
{
// Record start time
long long start = PerformanceCounter();
function();
long long finish = PerformanceCounter();
long long frequency = PerformanceFrequency();
double elapsedMilliseconds = ((finish - start) * 1000.0) / frequency;
return 0;
}