POCO Foundation::DateTime::Clock
An object of class Clock stores a monotonic clock value with (theoretical) microseconds resolution. Clocks can be compared with each other and simple arithmetic is supported.Monotonic Clock is available on Windows, Linux, OS X and on POSIX platforms supporting clock_gettime() with CLOCK_MONOTONIC.
Clock values are relative to a system-dependent epoch time (usually the system's startup time) and have no relation to the time of day.Note that Clock values are only monotonic if the operating system provides a monotonic clock. The monotonic() function can be used to check whether the system's clock is monotonic.
Types defined and used:
typedef Int64 ClockDiff;
Difference between two ClockVal values in microseconds.
typedef Int64 ClockVal;
Monotonic clock value in microsecond resolution.
Variables of class:
static const ClockVal CLOCKVAL_MAX;
Maximum clock value.
static const ClockVal CLOCKVAL_MIN;
Minimum clock value.
Member functions of this class:
static bool monotonic()
Returns true if and only if the system's clock is monotonic.
Clock()
Creates a Clock with the current system clock value.
ClockVal raw() const
Returns the clock value expressed in microseconds since the system-specific epoch time (usually system startup).
ClockDiff elapsed() const
Returns the time elapsed since the time denoted by the Clock instance.
ClockDiff operator - (const Clock & ts) const
Returns Clockdifference of calling object and ts
bool operator > (const Clock & ts) const
Returns true if clockval of calling object is greater than clockval of ts
Similarly <,==,!=,<=,>= are also overloaded
void update()
Updates the Clock with the current system clock.
The following program demonstrates the basic operations
#include "Poco/Clock.h"
#include <iostream>
using Poco::Clock;
int main()
{
if (Poco::Clock::monotonic())
std::cout << "clock is monotonic\n";
else
std::cout << "clock is non monotonic\n";
std::cout <<"CLOCKVAL_MAX :"<< Poco::Clock::CLOCKVAL_MAX << std::endl;
std::cout <<"CLOCKVAL_MIN :"<< Poco::Clock::CLOCKVAL_MIN << std::endl;
Clock a = Clock();
std::cout <<"a.raw() :" <<a.raw() << std::endl;
std::cout << "a.elapsed() :" << a.elapsed() << std::endl;
Clock b = Clock();
std::cout << "b.raw() :" << b.raw() << std::endl;
std::cout <<"b-a :" <<b - a << std::endl;
a.update();
std::cout << "a.raw() after a.update() :" <<a.raw()<< std::endl;
if (a > b)
std::cout <<"a-b :"<< a - b << std::endl;
else
std::cout <<"b-a"<< b - a << std::endl;
return 0;
}
Output:
clock is monotonic
CLOCKVAL_MAX :9223372036854775807
CLOCKVAL_MIN :-9223372036854775808
a.raw() :14523150483
a.elapsed() :569
b.raw() :14523151289
b-a :806
a.raw() after a.update() :14523152183
a-b :894
Comments