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-2016 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 "spxdefines.h"
32 #include "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 = long(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  lasttime = 0;
83 }
84 
85 // stop timer, return accounted user time.
87 {
88  // status remains unchanged if timer is not running
89  if (status == RUNNING)
90  {
91  updateTicks();
92 
93  uAccount += uTicks;
94  status = STOPPED;
95  }
96  return ticks2sec(uAccount);
97 }
98 
99 // get accounted user time.
101 {
102  if (status == RUNNING)
103  {
104  updateTicks();
106  }
107  else
108  {
110  }
111  return lasttime;
112 }
113 
115 {
116  return lasttime;
117 }
118 
119 } // namespace soplex
long uAccount
user time
Definition: usertimer.h:42
void updateTicks() const
get actual user ticks from the system.
Definition: usertimer.cpp:52
long uTicks
user ticks
Definition: usertimer.h:43
double Real
SOPLEX_DEBUG.
Definition: spxdefines.h:200
virtual Real lastTime() const
Definition: usertimer.cpp:114
virtual Real time() const
Definition: usertimer.cpp:100
virtual Real stop()
stop timer, return accounted user time.
Definition: usertimer.cpp:86
enum soplex::Timer::@18 status
status of the timer
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
Everything should be within this namespace.
UserTimer class.
Real ticks2sec(long ticks) const
convert ticks to secounds.
Definition: usertimer.h:52
static const long ticks_per_sec
ticks per secound, should be constant
Definition: usertimer.h:36