fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::IntervalTimer Class Reference

High resolution interval timer. More...

#include <timer.hpp>

Public Member Functions

 IntervalTimer ()
 Ctor. RAII. More...
 
virtual ~IntervalTimer ()
 Dtor. More...
 
const IntervalTimerCalculate ()
 
double AsDouble () const
 
double Reset ()
 

Private Attributes

Tickval startTime_
 
Tickval delta_
 

Friends

std::ostream & operator<< (std::ostream &os, const IntervalTimer &what)
 

Detailed Description

High resolution interval timer.

Definition at line 241 of file timer.hpp.

Constructor & Destructor Documentation

FIX8::IntervalTimer::IntervalTimer ( )
inline

Ctor. RAII.

Definition at line 254 of file timer.hpp.

254 : startTime_(true) {}
Tickval startTime_
Definition: timer.hpp:246
virtual FIX8::IntervalTimer::~IntervalTimer ( )
inlinevirtual

Dtor.

Definition at line 258 of file timer.hpp.

258 {}

Member Function Documentation

double FIX8::IntervalTimer::AsDouble ( ) const
inline

Get delta as a double.

Returns
delta as double

Definition at line 278 of file timer.hpp.

References FIX8::Tickval::todouble().

Referenced by FIX8::Message::encode(), FIX8::Message::factory(), and Reset().

278 { return delta_.todouble(); }
double todouble() const
Definition: tickval.hpp:166
const IntervalTimer& FIX8::IntervalTimer::Calculate ( )
inline

Calculate elapsed time (delta).

Returns
reference to this object

Definition at line 262 of file timer.hpp.

References startTime_.

Referenced by FIX8::Message::encode(), and FIX8::Message::factory().

263  {
264 #if defined FIX8_USE_RDTSC && defined FIX8_HAVE_RDTSC
265  Tickval::ticks now(rdtsc());
266 #else
267  Tickval now(true);
268 #endif
269  delta_ = now - startTime_;
270  return *this;
271  }
Tickval startTime_
Definition: timer.hpp:246
decltype(f8_time_point::min().time_since_epoch().count()) ticks
Definition: tickval.hpp:66
double FIX8::IntervalTimer::Reset ( )
inline

Reset the interval start time.

Returns
the old delta as double

Definition at line 283 of file timer.hpp.

References AsDouble(), and FIX8::Tickval::now().

284  {
285 #if defined FIX8_USE_RDTSC && defined FIX8_HAVE_RDTSC
286  const Tickval::ticks curr(delta_);
287  startTime_ = rdtsc();
288 #else
289  const double curr(AsDouble());
290  startTime_.now();
291 #endif
292  return curr;
293  }
Tickval startTime_
Definition: timer.hpp:246
Tickval & now()
Definition: tickval.hpp:133
decltype(f8_time_point::min().time_since_epoch().count()) ticks
Definition: tickval.hpp:66
double AsDouble() const
Definition: timer.hpp:278

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const IntervalTimer what 
)
friend

Format the interval to 9 decimal places, insert into stream.

Parameters
osthe stream to insert into
whatthe IntervalTimer object
Returns
the stream, os

Definition at line 299 of file timer.hpp.

300  {
301  std::ostringstream ostr;
302  ostr.setf(std::ios::showpoint);
303  ostr.setf(std::ios::fixed);
304 #if defined FIX8_USE_RDTSC && defined FIX8_HAVE_RDTSC
305  ostr << std::setprecision(9) << what;
306 #else
307  ostr << std::setprecision(9) << what.AsDouble();
308 #endif
309  return os << ostr.str();
310  }

Member Data Documentation

Tickval FIX8::IntervalTimer::delta_
private

Definition at line 246 of file timer.hpp.

Tickval FIX8::IntervalTimer::startTime_
private

Definition at line 246 of file timer.hpp.

Referenced by Calculate().


The documentation for this class was generated from the following file: