forked from organicmaps/organicmaps
[core] Added HighResTimer for benchmarks.
This commit is contained in:
parent
9c448faaf3
commit
70c2c746a1
3 changed files with 47 additions and 0 deletions
|
@ -157,4 +157,20 @@ time_t StringToTimestamp(string const & s)
|
|||
return res;
|
||||
}
|
||||
|
||||
HighResTimer::HighResTimer(bool start/* = true*/)
|
||||
{
|
||||
if (start)
|
||||
Reset();
|
||||
}
|
||||
|
||||
void HighResTimer::Reset()
|
||||
{
|
||||
m_start = high_resolution_clock::now();
|
||||
}
|
||||
|
||||
uint64_t HighResTimer::ElapsedNano() const
|
||||
{
|
||||
return duration_cast<nanoseconds>(high_resolution_clock::now() - m_start).count();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "../std/stdint.hpp"
|
||||
#include "../std/string.hpp"
|
||||
#include "../std/ctime.hpp"
|
||||
#include "../std/chrono.hpp"
|
||||
|
||||
|
||||
namespace my
|
||||
|
@ -37,4 +38,18 @@ time_t const INVALID_TIME_STAMP = -1;
|
|||
/// @return INVALID_TIME_STAMP if string is invalid
|
||||
time_t StringToTimestamp(string const & s);
|
||||
|
||||
|
||||
/// High resolution timer to use in comparison tests.
|
||||
class HighResTimer
|
||||
{
|
||||
typedef high_resolution_clock::time_point PointT;
|
||||
PointT m_start;
|
||||
|
||||
public:
|
||||
explicit HighResTimer(bool start = true);
|
||||
|
||||
void Reset();
|
||||
uint64_t ElapsedNano() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
16
std/chrono.hpp
Normal file
16
std/chrono.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
#include "common_defines.hpp"
|
||||
|
||||
#ifdef new
|
||||
#undef new
|
||||
#endif
|
||||
|
||||
#include <chrono>
|
||||
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::nanoseconds;
|
||||
using std::chrono::duration_cast;
|
||||
|
||||
#ifdef DEBUG_NEW
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
Loading…
Add table
Reference in a new issue