Implement Timer class

This commit is contained in:
ζeh Matt 2021-12-02 17:07:40 +02:00
parent cb6d7418c5
commit 30cc3dff3f
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,34 @@
/*****************************************************************************
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <chrono>
namespace OpenRCT2
{
class Timer
{
using Clock = std::chrono::high_resolution_clock;
using Timepoint = Clock::time_point;
Timepoint _tp = Clock::now();
public:
void Restart() noexcept
{
_tp = Clock::now();
}
float GetElapsed() const noexcept
{
auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() - _tp);
return static_cast<float>(static_cast<double>(elapsed.count()) / 1'000'000.0);
}
};
} // namespace OpenRCT2

View File

@ -187,6 +187,7 @@
<ClInclude Include="core\String.hpp" />
<ClInclude Include="core\StringBuilder.h" />
<ClInclude Include="core\StringReader.h" />
<ClInclude Include="core\Timer.hpp" />
<ClInclude Include="core\Zip.h" />
<ClInclude Include="core\ZipStream.hpp" />
<ClInclude Include="Date.h" />