Simplify Clocks.

GitOrigin-RevId: 6684cd9d98efea14d00317d1975b58aa7e2c8a11
This commit is contained in:
levlam 2020-04-08 02:39:51 +03:00
parent 301ff466e1
commit b35862bd71
2 changed files with 7 additions and 17 deletions

View File

@ -10,12 +10,13 @@
namespace td {
ClocksDefault::Duration ClocksDefault::monotonic() {
double Clocks::monotonic() {
// TODO write system specific functions, because std::chrono::steady_clock is steady only under Windows
auto duration = std::chrono::steady_clock::now().time_since_epoch();
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
}
ClocksDefault::Duration ClocksDefault::system() {
double Clocks::system() {
auto duration = std::chrono::system_clock::now().time_since_epoch();
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
}

View File

@ -8,21 +8,10 @@
namespace td {
class ClocksBase {
public:
using Duration = double;
struct Clocks {
static double monotonic();
static double system();
};
// TODO: (maybe) write system specific functions.
class ClocksDefault {
public:
using Duration = ClocksBase::Duration;
static Duration monotonic();
static Duration system();
};
using Clocks = ClocksDefault;
} // namespace td