Scippy

SoPlex

Sequential object-oriented simPlex

usertimer.cpp
Go to the documentation of this file.
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 #include <assert.h>
26 
27 #if defined(_WIN32) || defined(_WIN64)
28 
29 #include <time.h>
30 
31 #else // !(_WIN32 || _WIN64)
32 
33 #include <sys/types.h>
34 #include <sys/times.h>
35 //#include <sys/param.h>
36 #include <unistd.h>
37 
38 #endif // !(_WIN32 || _WIN64)
39 
40 #include "soplex/spxdefines.h"
41 #include "soplex/usertimer.h"
42 
43 namespace soplex
44 {
45 /* determine TIMES_TICKS_PER_SEC for clock ticks delivered by times().
46  * (don't use CLOCKS_PER_SEC since this is related to clock() only).
47  */
48 #if defined(CLK_TCK)
49 #define TIMES_TICKS_PER_SEC CLK_TCK
50 #elif defined(_SC_CLK_TCK)
51 #define TIMES_TICKS_PER_SEC sysconf(_SC_CLK_TCK)
52 #elif defined(HZ)
53 #define TIMES_TICKS_PER_SEC HZ
54 #else // !CLK_TCK && !_SC_CLK_TCK && !HZ
55 #define TIMES_TICKS_PER_SEC 60
56 #endif // !CLK_TCK && !_SC_CLK_TCK && !HZ
57 
59 
60 // get actual user, system and real time from system
62 {
63 #if defined(_WIN32) || defined(_WIN64)
64 
65  uTicks = clock();
66 
67 #else /* !(_WIN32 || _WIN64) */
68 
69  struct tms now;
70  clock_t ret = times(&now);
71 
72  if(int(ret) == -1)
73  now.tms_utime = now.tms_stime = ret = 0;
74 
75  uTicks = now.tms_utime;
76 
77 #endif /* !(_WIN32 || _WIN64) */
78 }
79 
80 // start timer, resume accounting user, system and real time.
82 {
83  // ignore start request if timer is running
84  if(status != RUNNING)
85  {
86  updateTicks();
87 
88  uAccount -= uTicks;
89  status = RUNNING;
90  }
91 
92  lasttime = 0;
93 }
94 
95 // stop timer, return accounted user time.
97 {
98  // status remains unchanged if timer is not running
99  if(status == RUNNING)
100  {
101  updateTicks();
102 
103  uAccount += uTicks;
104  status = STOPPED;
105  }
106 
107  return ticks2sec(uAccount);
108 }
109 
110 // get accounted user time.
112 {
113  if(status == RUNNING)
114  {
115  updateTicks();
117  }
118  else
119  {
121  }
122 
123  return lasttime;
124 }
125 
127 {
128  return lasttime;
129 }
130 
131 } // namespace soplex
clock_t uAccount
user time
Definition: usertimer.h:51
clock_t uTicks
user ticks
Definition: usertimer.h:52
virtual Real lastTime() const
Definition: usertimer.cpp:126
double Real
Definition: spxdefines.h:269
virtual Real time() const
Definition: usertimer.cpp:111
virtual Real stop()
stop timer, return accounted user time.
Definition: usertimer.cpp:96
virtual void start()
start timer, resume accounting user, system and real time.
Definition: usertimer.cpp:81
Debugging, floating point type and parameter definitions.
#define TIMES_TICKS_PER_SEC
Definition: usertimer.cpp:55
Real ticks2sec(clock_t ticks) const
convert ticks to secounds.
Definition: usertimer.h:61
Everything should be within this namespace.
UserTimer class.
static const long ticks_per_sec
ticks per secound, should be constant
Definition: usertimer.h:45
enum soplex::Timer::@15 status
status of the timer
void updateTicks() const
get actual user ticks from the system.
Definition: usertimer.cpp:61