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 usertimer.h 26 * @brief UserTimer class. 27 */ 28 29 #ifndef _USER_TIMER_H_ 30 #define _USER_TIMER_H_ 31 32 #include "soplex/spxdefines.h" 33 #include "soplex/timer.h" 34 35 namespace soplex 36 { 37 38 class UserTimer : public Timer 39 { 40 private: 41 42 //------------------------------------ 43 /**@name number of ticks per second */ 44 ///@{ 45 static const long ticks_per_sec; ///< ticks per secound, should be constant 46 ///@} 47 48 //------------------------------------ 49 /**@name Data */ 50 ///@{ 51 mutable clock_t uAccount; ///< user time 52 mutable clock_t uTicks; ///< user ticks 53 54 mutable Real lasttime; 55 ///@} 56 57 //------------------------------------ 58 /**@name Internal helpers */ 59 ///@{ 60 /// convert ticks to secounds. 61 Real ticks2sec(clock_t ticks) const 62 { 63 return (Real(ticks) * 1000.0 / Real(ticks_per_sec)) / 1000.0; 64 } 65 66 /// get actual user ticks from the system. 67 void updateTicks() const; 68 69 ///@} 70 71 public: 72 73 //------------------------------------ 74 /**@name Construction / destruction */ 75 ///@{ 76 /// default constructor 77 UserTimer() 78 : Timer(), uAccount(0), uTicks(0), lasttime(0.0) 79 { 80 assert(ticks_per_sec > 0); 81 } 82 /// copy constructor 83 UserTimer(const UserTimer& old) 84 : Timer(), uAccount(old.uAccount), uTicks(old.uTicks), lasttime(old.lasttime) 85 { 86 assert(ticks_per_sec > 0); 87 } 88 /// assignment operator 89 UserTimer& operator=(const UserTimer& old) 90 { 91 assert(ticks_per_sec > 0); 92 uAccount = old.uAccount; 93 uTicks = old.uTicks; 94 lasttime = old.lasttime; 95 return *this; 96 } 97 98 virtual ~UserTimer() 99 {} 100 ///@} 101 102 //------------------------------------ 103 /**@name Control */ 104 ///@{ 105 /// initialize timer, set timing accounts to zero. 106 virtual void reset() 107 { 108 status = RESET; 109 uAccount = 0; 110 lasttime = 0.0; 111 } 112 113 /// start timer, resume accounting user, system and real time. 114 virtual void start(); 115 116 /// stop timer, return accounted user time. 117 virtual Real stop(); 118 119 /// return type of timer 120 virtual TYPE type() 121 { 122 return USER_TIME; 123 } 124 ///@} 125 126 //------------------------------------ 127 /**@name Access */ 128 ///@{ 129 virtual Real time() const; 130 131 virtual Real lastTime() const; 132 ///@} 133 }; 134 } // namespace soplex 135 #endif // _USER_TIMER_H_ 136