forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
95 lines (77 loc) · 2.17 KB
/
Copy pathtimer.h
File metadata and controls
95 lines (77 loc) · 2.17 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#pragma once
#include <chrono>
using namespace std::chrono;
class CTimer
{
private:
steady_clock::time_point startPerfomanceCount;
steady_clock::time_point endPerfomanceCount;
duration<float> totalElapsed;
public:
char m_szMessage[1024];
public:
CTimer()
{
Initialize();
}
CTimer(bool bStartOnCreate)
{
Initialize();
if (bStartOnCreate)
{
Start();
}
}
void Initialize()
{
totalElapsed = duration<float>();
}
void Start()
{
startPerfomanceCount = std::chrono::steady_clock::now();
}
// time unit: seconds
void Tag(const char* pszMsg = NULL)
{
endPerfomanceCount = std::chrono::steady_clock::now();
totalElapsed += duration_cast<duration<float>> (endPerfomanceCount - startPerfomanceCount);
OutputStatistics(pszMsg);
//start next round
Start();
}
// time unit: seconds
void InnerTag()
{
endPerfomanceCount = std::chrono::steady_clock::now();
totalElapsed += duration_cast<duration<float>> (endPerfomanceCount - startPerfomanceCount);
OutputStatistics(m_szMessage);
//start next round
Start();
}
float GetTotalElaps()
{
return totalElapsed.count();
}
float GetTimeSpan()
{
endPerfomanceCount = std::chrono::steady_clock::now();
totalElapsed += duration_cast<duration<float>> (endPerfomanceCount - startPerfomanceCount);
float timespent = totalElapsed.count();
//start next round
Start();
return timespent;
}
float GetTaggedTimeSpan()
{
return duration_cast<duration<float>> (endPerfomanceCount - startPerfomanceCount).count();
}
void OutputStatistics(const char* pszMsg = NULL)
{
printf("Time Cost totally: %f, last time span(%s): %f seconds.\n", GetTotalElaps(), pszMsg, GetTaggedTimeSpan());
}
private:
CTimer(const CTimer& obj);
};