Go to the documentation of this file.00001 #include "constraint_aware_spline_smoother/ParabolicPathSmooth/Timer.h"
00002 #include <stdlib.h>
00003 using namespace ParabolicRamp;
00004
00005 #ifdef WIN32
00006 #define GETCURRENTTIME(x) x=timeGetTime()
00007 #else
00008 #ifdef _POSIX_MONOTONIC_CLOCK
00009 #define GETCURRENTTIME(x) clock_gettime(CLOCK_MONOTONIC,&x)
00010 #else
00011 #define GETCURRENTTIME(x) gettimeofday(&x,NULL)
00012 #endif //_POSIX_MONOTONIC_CLOCK
00013 #endif //WIN32
00014
00015
00016
00017
00018 #if defined (__SVR4) && defined (__sun)
00019 #include "timersub.h"
00020 #endif
00021
00022 Timer::Timer()
00023 {
00024 Reset();
00025 }
00026
00027 void Timer::Reset()
00028 {
00029 GETCURRENTTIME(start);
00030 current=start;
00031 }
00032
00033 long long Timer::ElapsedTicks()
00034 {
00035 GETCURRENTTIME(current);
00036 return LastElapsedTicks();
00037 }
00038
00039 long long Timer::LastElapsedTicks() const
00040 {
00041 #ifdef WIN32
00042 return current-start;
00043 #else
00044 #ifdef _POSIX_MONOTONIC_CLOCK
00045 long long ticks = (current.tv_sec-start.tv_sec)*1000 + (current.tv_nsec-start.tv_nsec)/1000000;
00046 return ticks;
00047 #else
00048 timeval delta;
00049 timersub(¤t,&start,&delta);
00050 long long ticks = delta.tv_sec*1000 + delta.tv_usec/1000;
00051 return ticks;
00052 #endif //_POSIX_MONOTONIC_CLOCK
00053 #endif //WIN32
00054 }
00055
00056 double Timer::ElapsedTime()
00057 {
00058 GETCURRENTTIME(current);
00059 return LastElapsedTime();
00060 }
00061
00062 double Timer::LastElapsedTime() const
00063 {
00064 #ifdef WIN32
00065 return double(current-start)/1000.0;
00066 #else
00067 #ifdef _POSIX_MONOTONIC_CLOCK
00068 double secs=double(current.tv_sec-start.tv_sec);
00069 secs += double(current.tv_nsec-start.tv_nsec)/1000000000.0;
00070 return secs;
00071 #else
00072 timeval delta;
00073 timersub(¤t,&start,&delta);
00074 double secs=double(delta.tv_sec);
00075 secs += double(delta.tv_usec)/1000000.0;
00076 return secs;
00077 #endif //_POSIX_MONOTONIC_CLOCK
00078 #endif //WIN32
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103