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-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 #include <assert.h>
17 
18 #if defined(_WIN32) || defined(_WIN64)
19 
20 #include <time.h>
21 
22 #else // !(_WIN32 || _WIN64)
23 
24 #include <sys/types.h>
25 #include <sys/times.h>
26 //#include <sys/param.h>
27 #include <unistd.h>
28 
29 #endif // !(_WIN32 || _WIN64)
30 
31 #include "soplex/spxdefines.h"
32 #include "soplex/usertimer.h"
33 
34 namespace soplex
35 {
36 /* determine TIMES_TICKS_PER_SEC for clock ticks delivered by times().
37  * (don't use CLOCKS_PER_SEC since this is related to clock() only).
38  */
39 #if defined(CLK_TCK)
40 #define TIMES_TICKS_PER_SEC CLK_TCK
41 #elif defined(_SC_CLK_TCK)
42 #define TIMES_TICKS_PER_SEC sysconf(_SC_CLK_TCK)
43 #elif defined(HZ)
44 #define TIMES_TICKS_PER_SEC HZ
45 #else // !CLK_TCK && !_SC_CLK_TCK && !HZ
46 #define TIMES_TICKS_PER_SEC 60
47 #endif // !CLK_TCK && !_SC_CLK_TCK && !HZ
48 
50 
51 // get actual user, system and real time from system
53 {
54 #if defined(_WIN32) || defined(_WIN64)
55 
56  uTicks = clock();
57 
58 #else /* !(_WIN32 || _WIN64) */
59 
60  struct tms now;
61  clock_t ret = times(&now);
62 
63  if(int(ret) == -1)
64  now.tms_utime = now.tms_stime = ret = 0;
65 
66  uTicks = now.tms_utime;
67 
68 #endif /* !(_WIN32 || _WIN64) */
69 }
70 
71 // start timer, resume accounting user, system and real time.
73 {
74  // ignore start request if timer is running
75  if(status != RUNNING)
76  {
77  updateTicks();
78 
79  uAccount -= uTicks;
80  status = RUNNING;
81  }
82 
83  lasttime = 0;
84 }
85 
86 // stop timer, return accounted user time.
88 {
89  // status remains unchanged if timer is not running
90  if(status == RUNNING)
91  {
92  updateTicks();
93 
94  uAccount += uTicks;
95  status = STOPPED;
96  }
97 
98  return ticks2sec(uAccount);
99 }
100 
101 // get accounted user time.
103 {
104  if(status == RUNNING)
105  {
106  updateTicks();
108  }
109  else
110  {
112  }
113 
114  return lasttime;
115 }
116 
118 {
119  return lasttime;
120 }
121 
122 } // namespace soplex
clock_t uAccount
user time
Definition: usertimer.h:42
clock_t uTicks
user ticks
Definition: usertimer.h:43
enum soplex::Timer::@2 status
status of the timer
virtual Real lastTime() const
Definition: usertimer.cpp:117
double Real
Definition: spxdefines.h:256
virtual Real time() const
Definition: usertimer.cpp:102
virtual Real stop()
stop timer, return accounted user time.
Definition: usertimer.cpp:87
virtual void start()
start timer, resume accounting user, system and real time.
Definition: usertimer.cpp:72
Debugging, floating point type and parameter definitions.
#define TIMES_TICKS_PER_SEC
Definition: usertimer.cpp:46
Real ticks2sec(clock_t ticks) const
convert ticks to secounds.
Definition: usertimer.h:52
Everything should be within this namespace.
UserTimer class.
static const long ticks_per_sec
ticks per secound, should be constant
Definition: usertimer.h:36
void updateTicks() const
get actual user ticks from the system.
Definition: usertimer.cpp:52