diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 7a5ade09..c464ff11 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -40,6 +40,7 @@ + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index ba792afa..6ed44123 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -19,5 +19,6 @@ + \ No newline at end of file diff --git a/Common/Timer.h b/Common/Timer.h new file mode 100644 index 00000000..3b406d2e --- /dev/null +++ b/Common/Timer.h @@ -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 + +// 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