00001 //===========================================================================// 00002 // This file is part of the DIP Solver Framework. // 00003 // // 00004 // DIP is distributed under the Eclipse Public License as part of the // 00005 // COIN-OR repository (http://www.coin-or.org). // 00006 // // 00007 // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) // 00008 // // 00009 // Conceptual Design: Matthew Galati, SAS Institute Inc. // 00010 // Ted Ralphs, Lehigh University // 00011 // // 00012 // Copyright (C) 2002-2015, Lehigh University, Matthew Galati, and Ted Ralphs// 00013 // All Rights Reserved. // 00014 //===========================================================================// 00015 00016 #ifndef UTIL_TIMER_INCLUDED 00017 #define UTIL_TIMER_INCLUDED 00018 00019 //===========================================================================// 00020 #include "CoinTime.hpp" 00021 00022 //===========================================================================// 00023 /* A timer used to record cpu and wallclock time. */ 00024 class UtilTimer { 00025 private: 00027 double startCpu_; 00028 double finishCpu_; 00029 double startReal_; 00030 double finishReal_; 00031 00033 double cpu_; 00034 00036 double real_; 00037 00038 public: 00039 UtilTimer() { 00040 reset(); 00041 } 00042 ~UtilTimer() {} 00043 00045 inline void reset() { 00046 start(); 00047 finishCpu_ = 0.0; 00048 finishReal_ = 0.0; 00049 cpu_ = 0.0; 00050 real_ = 0.0; 00051 } 00052 00054 inline void start() { 00055 startCpu_ = CoinCpuTime(); 00056 startReal_ = CoinGetTimeOfDay(); 00057 } 00058 00060 inline void stop() { 00061 finishCpu_ = CoinCpuTime(); 00062 finishReal_ = CoinGetTimeOfDay(); 00063 cpu_ = finishCpu_ - startCpu_; 00064 real_ = finishReal_ - startReal_; 00065 } 00066 00068 inline double getCpuTime() { 00069 finishCpu_ = CoinCpuTime(); 00070 cpu_ = finishCpu_ - startCpu_; 00071 return cpu_; 00072 } 00073 00075 inline double getRealTime() { 00076 finishReal_ = CoinGetTimeOfDay(); 00077 real_ = finishReal_ - startReal_; 00078 return real_; 00079 } 00080 00083 inline bool isPast(double limit) { 00084 return (getRealTime() > limit); 00085 } 00086 00087 }; 00088 00089 #endif