52 #ifndef __PCL_ElapsedTime_h
53 #define __PCL_ElapsedTime_h
58 #include <pcl/Diagnostics.h>
62 #if !defined( __PCL_LINUX ) && !defined( __PCL_FREEBSD )
65 # define PCL_CLOCK_ID 0
70 # ifdef CLOCK_MONOTONIC_RAW
71 # define PCL_CLOCK_ID CLOCK_MONOTONIC_RAW
73 # define PCL_CLOCK_ID CLOCK_MONOTONIC
78 # include <sys/timespec.h>
79 # ifdef CLOCK_MONOTONIC_PRECISE
80 # define PCL_CLOCK_ID CLOCK_MONOTONIC_PRECISE
82 # define PCL_CLOCK_ID CLOCK_MONOTONIC
87 # include <mach/mach.h>
88 # include <mach/mach_time.h>
160 double operator ()()
const
162 return TimeStamp() - m_start;
171 m_start = TimeStamp();
181 return ToIsoString(
operator()() );
191 return ToString(
operator()() );
199 return ToIsoString();
222 #if defined( __PCL_LINUX ) || defined( __PCL_FREEBSD )
228 (void)clock_gettime( PCL_CLOCK_ID, &ts );
229 return ts.tv_sec + ts.tv_nsec*1.0e-09;
243 static double absoluteToSeconds;
249 if ( initialized.
Load() == 0 )
251 mach_timebase_info_data_t timeBase = { 0 };
252 mach_timebase_info( &timeBase );
253 absoluteToSeconds = 1.0e-09*(double( timeBase.numer )/timeBase.denom);
254 offset = mach_absolute_time();
255 initialized.
Store( 1 );
259 uint64 t = mach_absolute_time();
260 return (t - offset)*absoluteToSeconds;
276 static double countsToSeconds;
282 if ( initialized.
Load() == 0 )
284 uint64 performanceFrequency;
285 QueryPerformanceFrequency( (LARGE_INTEGER*)&performanceFrequency );
286 countsToSeconds = 1.0/performanceFrequency;
287 QueryPerformanceCounter( (LARGE_INTEGER*)&offset );
288 initialized.
Store( 1 );
293 QueryPerformanceCounter( (LARGE_INTEGER*)&t );
294 return (t - offset)*countsToSeconds;
330 return ToString( seconds, width, precision, (
IsoString*)0 );
340 return ToString( s, width, precision, (
String*)0 );
352 return t1.m_start - t2.m_start;
360 static S ToString(
double s,
int w,
int p, S* )
363 p =
Range( p, 0, 3 );
369 w =
Max( p+2, w+p+1 );
386 return S().Format(
"%*.*f %s", w, p, s, u );
387 return S().Format(
"%.*f %s", p, s, u );
390 int sign = (s < 0) ? -1 : +1;
398 return S().Format(
"%02d:%0*.*f", m*sign, (p > 0) ? 3+p : 2, p, s );
408 return S().Format(
"%02d:%02d:%0*.*f", h*sign, m, (p > 0) ? 3+p : 2, p, s );
417 return S().Format(
"%d:%02d:%02d:%02d", d*sign, h, m,
RoundInt( s ) );
Atomic operations on integers.
Automatic mutex lock/unlock.
High-resolution time stamp.
ElapsedTime(const ElapsedTime &)=default
IsoString ToIsoString() const
static double TimeStamp()
static IsoString ToIsoString(double seconds, int width=0, int precision=3)
static String ToString(double s, int width=0, int precision=3)
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Adaptive mutual exclusion lock variable.
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
T Abs(const Complex< T > &c) noexcept
int RoundInt(T x) noexcept
int TruncInt(T x) noexcept
unsigned long long uint64
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept