Common: Add Timer.h

This commit is contained in:
Birunthan Mohanathas 2013-11-06 15:54:17 +02:00
parent fcc62a9ff3
commit 1be1381e7b
3 changed files with 58 additions and 0 deletions

View File

@ -40,6 +40,7 @@
<ClInclude Include="Platform.h" /> <ClInclude Include="Platform.h" />
<ClInclude Include="RawString.h" /> <ClInclude Include="RawString.h" />
<ClInclude Include="StringUtil.h" /> <ClInclude Include="StringUtil.h" />
<ClInclude Include="Timer.h" />
<ClInclude Include="UnitTest.h" /> <ClInclude Include="UnitTest.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -19,5 +19,6 @@
<ClInclude Include="ControlTemplate.h" /> <ClInclude Include="ControlTemplate.h" />
<ClInclude Include="MathParser.h" /> <ClInclude Include="MathParser.h" />
<ClInclude Include="UnitTest.h" /> <ClInclude Include="UnitTest.h" />
<ClInclude Include="Timer.h" />
</ItemGroup> </ItemGroup>
</Project> </Project>

56
Common/Timer.h Normal file
View 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