1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the class library */ 4 /* SoPlex --- the Sequential object-oriented simPlex. */ 5 /* */ 6 /* Copyright (c) 1996-2023 Zuse Institute Berlin (ZIB) */ 7 /* */ 8 /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 /* you may not use this file except in compliance with the License. */ 10 /* You may obtain a copy of the License at */ 11 /* */ 12 /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 /* */ 14 /* Unless required by applicable law or agreed to in writing, software */ 15 /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 /* See the License for the specific language governing permissions and */ 18 /* limitations under the License. */ 19 /* */ 20 /* You should have received a copy of the Apache-2.0 license */ 21 /* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */ 22 /* */ 23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 24 25 /**@file wallclocktimer.h 26 * @brief WallclockTimer class. 27 */ 28 29 #ifndef _WALLCLOCK_TIMER_H_ 30 #define _WALLCLOCK_TIMER_H_ 31 32 #include "soplex/spxdefines.h" 33 #include "soplex/timer.h" 34 35 namespace soplex 36 { 37 38 class WallclockTimer : public Timer 39 { 40 private: 41 42 //------------------------------------ 43 /**@name Data */ 44 ///@{ 45 mutable time_t sec; ///< seconds 46 mutable time_t usec; ///< microseconds 47 48 mutable Real lasttime; 49 ///@} 50 51 //------------------------------------ 52 /**@name Internal helpers */ 53 ///@{ 54 /// convert wallclock time to secounds. 55 Real wall2sec(time_t s, time_t us) const 56 { 57 return (Real)s + 0.000001 * (Real)us; 58 } 59 60 ///@} 61 62 public: 63 64 //------------------------------------ 65 /**@name Construction / destruction */ 66 ///@{ 67 /// default constructor 68 WallclockTimer() 69 : Timer(), sec(0), usec(0), lasttime(0.0) 70 {} 71 /// copy constructor 72 WallclockTimer(const WallclockTimer& old) 73 : Timer(), sec(old.sec), usec(old.usec), lasttime(old.lasttime) 74 {} 75 /// assignment operator 76 WallclockTimer& operator=(const WallclockTimer& old) 77 { 78 sec = old.sec; 79 usec = old.usec; 80 lasttime = old.lasttime; 81 return *this; 82 } 83 84 virtual ~WallclockTimer() 85 {} 86 ///@} 87 88 //------------------------------------ 89 /**@name Control */ 90 ///@{ 91 /// initialize timer, set timing accounts to zero. 92 virtual void reset() 93 { 94 status = RESET; 95 sec = usec = 0; 96 lasttime = 0.0; 97 } 98 99 /// start timer, resume accounting user, system and real time. 100 virtual void start(); 101 102 /// stop timer, return accounted user time. 103 virtual Real stop(); 104 105 /// return type of timer 106 virtual TYPE type() 107 { 108 return WALLCLOCK_TIME; 109 } 110 ///@} 111 112 //------------------------------------ 113 /**@name Access */ 114 ///@{ 115 virtual Real time() const; 116 117 virtual Real lastTime() const; 118 119 ///@} 120 }; 121 } // namespace soplex 122 #endif // _WALLCLOCK_TIMER_H_ 123