19 # pragma warning(disable:4786) 22 #if defined(__MACH__) || defined (__FreeBSD__) 25 #if !defined(__MSVCRT__) 27 #include <sys/types.h> 29 #include <sys/resource.h> 37 #if 0 // change this to 1 if want to use the win32 API 44 #define TWO_TO_THE_THIRTYTWO 4294967296.0 45 #define DELTA_EPOCH_IN_SECS 11644473600.0 50 GetSystemTimeAsFileTime(&ft);
51 double t = ft.dwHighDateTime * TWO_TO_THE_THIRTYTWO + ft.dwLowDateTime;
52 t = t/10000000.0 - DELTA_EPOCH_IN_SECS;
56 #include <sys/types.h> 57 #include <sys/timeb.h> 60 struct _timeb timebuffer;
61 #pragma warning(disable:4996) 62 _ftime( &timebuffer );
63 #pragma warning(default:4996) 64 return timebuffer.time + timebuffer.millitm/1000.0;
75 gettimeofday(&tv, NULL);
76 return static_cast<double>(tv.tv_sec) + static_cast<int>(tv.tv_usec)/1000000.0;
92 static const double firstCall = callType > 0 ? callType : callTime;
93 return callType < 0 ? firstCall : callTime - firstCall;
106 #define TWO_TO_THE_THIRTYTWO 4294967296.0 112 #if defined(_MSC_VER) || defined(__MSVCRT__) 118 GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user);
119 double t = user.dwHighDateTime * TWO_TO_THE_THIRTYTWO + user.dwLowDateTime;
122 unsigned int ticksnow;
123 ticksnow = (
unsigned int)clock();
124 cpu_temp = (double)((
double)ticksnow/CLOCKS_PER_SEC);
127 #elif defined(__KLIBC__) 129 unsigned int ticksnow;
130 ticksnow = (
unsigned int)clock();
131 cpu_temp = (double)((
double)ticksnow/CLOCKS_PER_SEC);
136 usage.ru_utime.tv_sec = 0 ;
137 usage.ru_utime.tv_usec = 0 ;
139 getrusage(RUSAGE_SELF,&usage);
140 cpu_temp =
static_cast<double>(usage.ru_utime.tv_sec);
141 cpu_temp += 1.0e-6*(
static_cast<double> (usage.ru_utime.tv_usec));
153 #if defined(_MSC_VER) || defined(__MSVCRT__) || defined(__KLIBC__) 158 usage.ru_utime.tv_sec = 0 ;
159 usage.ru_utime.tv_usec = 0 ;
161 getrusage(RUSAGE_SELF,&usage);
162 sys_temp =
static_cast<double>(usage.ru_stime.tv_sec);
163 sys_temp += 1.0e-6*(
static_cast<double> (usage.ru_stime.tv_usec));
173 #if defined(_MSC_VER) || defined(__MSVCRT__) || defined(__KLIBC__) 178 usage.ru_utime.tv_sec = 0 ;
179 usage.ru_utime.tv_usec = 0 ;
181 getrusage(RUSAGE_CHILDREN,&usage);
182 cpu_temp =
static_cast<double>(usage.ru_utime.tv_sec);
183 cpu_temp += 1.0e-6*(
static_cast<double> (usage.ru_utime.tv_usec));
214 #ifdef COIN_COMPILE_WITH_TRACING 215 std::fstream* stream;
220 #ifdef COIN_COMPILE_WITH_TRACING 221 inline bool evaluate(
bool b_tmp)
const {
225 (*stream) << i_tmp <<
"\n";
231 inline double evaluate(
double d_tmp)
const {
234 (*stream) << d_tmp <<
"\n";
241 inline bool evaluate(
const bool b_tmp)
const {
244 inline double evaluate(
const double d_tmp)
const {
252 start(0), limit(1e100), end(1e100)
253 #ifdef COIN_COMPILE_WITH_TRACING
254 , stream(0), write_stream(true)
261 #ifdef COIN_COMPILE_WITH_TRACING
262 , stream(0), write_stream(true)
266 #ifdef COIN_COMPILE_WITH_TRACING 270 start(0), limit(1e100), end(1e100),
271 stream(s), write_stream(write) {}
275 CoinTimer(
double lim, std::fstream* s,
bool w) :
277 stream(s), write_stream(w) {}
290 return evaluate(start + limit * pct <
CoinCpuTime());
void restart()
Restart the timer (keeping the same time limit)
double timeLeft() const
Return how much time is left on the timer.
double timeElapsed() const
Return how much time has elapsed.
bool isPast(double lim) const
Return whether the given amount of time has elapsed since the timer was started.
static double CoinCpuTime()
bool isExpired() const
Return whether the originally specified time limit has passed since the timer was started...
This class implements a timer that also implements a tracing functionality.
static double CoinCpuTimeJustChildren()
double CoinGetTimeOfDay()
CoinTimer(double lim)
Create a timer with the given time limit and with no tracing.
void reset()
An alternate name for restart()
double CoinWallclockTime(double callType=0)
Query the elapsed wallclock time since the first call to this function.
bool isPastPercent(double pct) const
Return whether the given percentage of the time limit has elapsed since the timer was started...
void reset(double lim)
Reset (and restart) the timer and change its time limit.
CoinTimer()
Default constructor creates a timer with no time limit and no tracing.
static double CoinSysTime()