mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Common: Add Timer.h
This commit is contained in:
parent
fcc62a9ff3
commit
1be1381e7b
@ -40,6 +40,7 @@
|
||||
<ClInclude Include="Platform.h" />
|
||||
<ClInclude Include="RawString.h" />
|
||||
<ClInclude Include="StringUtil.h" />
|
||||
<ClInclude Include="Timer.h" />
|
||||
<ClInclude Include="UnitTest.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -19,5 +19,6 @@
|
||||
<ClInclude Include="ControlTemplate.h" />
|
||||
<ClInclude Include="MathParser.h" />
|
||||
<ClInclude Include="UnitTest.h" />
|
||||
<ClInclude Include="Timer.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
56
Common/Timer.h
Normal file
56
Common/Timer.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 2013 Rainmeter Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_COMMON_TIMER_H_
|
||||
#define RM_COMMON_TIMER_H_
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
// Performs timing using the high-resolution performance counter.
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
void Start()
|
||||
{
|
||||
QueryPerformanceCounter(&m_Start);
|
||||
}
|
||||
|
||||
void Stop()
|
||||
{
|
||||
QueryPerformanceCounter(&m_Stop);
|
||||
}
|
||||
|
||||
// Returns the elapsed time in milliseconds.
|
||||
double GetElapsed() const
|
||||
{
|
||||
static LARGE_INTEGER s_Frequency = []()
|
||||
{
|
||||
LARGE_INTEGER frequency;
|
||||
QueryPerformanceFrequency(&frequency);
|
||||
return frequency;
|
||||
} ();
|
||||
|
||||
return (m_Stop.QuadPart - m_Start.QuadPart) * 1000.0 / s_Frequency.QuadPart;
|
||||
}
|
||||
|
||||
private:
|
||||
LARGE_INTEGER m_Start;
|
||||
LARGE_INTEGER m_Stop;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user