SoPlex
Toggle main menu visibility
Loading...
Searching...
No Matches
src
soplex
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-2026 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
#ifdef _WIN32
28
29
#include <time.h>
30
31
#else
// !_WIN32
32
33
#include <sys/types.h>
34
#include <sys/times.h>
35
//#include <sys/param.h>
36
#include <unistd.h>
37
38
#endif
// !_WIN32
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
58
const
long
UserTimer::ticks_per_sec
= long(
TIMES_TICKS_PER_SEC
);
59
60
// get actual user, system and real time from system
61
void
UserTimer::updateTicks
()
const
62
{
63
#ifdef _WIN32
64
65
uTicks
= clock();
66
67
#else
// !_WIN32
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
78
}
79
80
// start timer, resume accounting user, system and real time.
81
void
UserTimer::start
()
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.
96
Real
UserTimer::stop
()
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.
111
Real
UserTimer::time
()
const
112
{
113
if
(
status
==
RUNNING
)
114
{
115
updateTicks
();
116
lasttime
=
ticks2sec
(
uTicks
+
uAccount
);
117
}
118
else
119
{
120
lasttime
=
ticks2sec
(
uAccount
);
121
}
122
123
return
lasttime
;
124
}
125
126
Real
UserTimer::lastTime
()
const
127
{
128
return
lasttime
;
129
}
130
131
}
// namespace soplex
soplex::Timer::RUNNING
@ RUNNING
running
Definition
timer.h:97
soplex::Timer::STOPPED
@ STOPPED
stopped
Definition
timer.h:96
soplex::Timer::status
enum soplex::Timer::@172027350133147052164065250373301051153114204073 status
status of the timer
soplex::UserTimer::stop
virtual Real stop()
stop timer, return accounted user time.
Definition
usertimer.cpp:96
soplex::UserTimer::lastTime
virtual Real lastTime() const
Definition
usertimer.cpp:126
soplex::UserTimer::uAccount
clock_t uAccount
user time
Definition
usertimer.h:51
soplex::UserTimer::start
virtual void start()
start timer, resume accounting user, system and real time.
Definition
usertimer.cpp:81
soplex::UserTimer::lasttime
Real lasttime
Definition
usertimer.h:54
soplex::UserTimer::time
virtual Real time() const
Definition
usertimer.cpp:111
soplex::UserTimer::ticks2sec
Real ticks2sec(clock_t ticks) const
convert ticks to secounds.
Definition
usertimer.h:61
soplex::UserTimer::updateTicks
void updateTicks() const
get actual user ticks from the system.
Definition
usertimer.cpp:61
soplex::UserTimer::uTicks
clock_t uTicks
user ticks
Definition
usertimer.h:52
soplex::UserTimer::ticks_per_sec
static const long ticks_per_sec
ticks per secound, should be constant
Definition
usertimer.h:45
soplex
Everything should be within this namespace.
soplex::Real
double Real
Definition
spxdefines.h:269
spxdefines.h
Debugging, floating point type and parameter definitions.
TIMES_TICKS_PER_SEC
#define TIMES_TICKS_PER_SEC
Definition
usertimer.cpp:55
usertimer.h
UserTimer class.
Generated by
1.17.0