Toggle navigation
SCIP Optimization Suite
SCIP
SoPlex
ZIMPL
UG
GCG
Documentation
SoPlex 6.0.3
SoPlex 5.0.2
SoPlex 4.0.2
SoPlex 3.1.0
SoPlex 3.0.1
SoPlex 2.2.1
SoPlex
Sequential object-oriented simPlex
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
soplex-repo
src
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-2015 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
49
const
long
UserTimer::ticks_per_sec
= long(
TIMES_TICKS_PER_SEC
);
50
51
// get actual user, system and real time from system
52
void
UserTimer::updateTicks
()
const
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.
72
void
UserTimer::start
()
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.
86
Real
UserTimer::stop
()
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.
100
Real
UserTimer::time
()
const
101
{
102
if
(
status
==
RUNNING
)
103
{
104
updateTicks
();
105
lasttime
=
ticks2sec
(
uTicks
+
uAccount
);
106
}
107
else
108
{
109
lasttime
=
ticks2sec
(
uAccount
);
110
}
111
return
lasttime
;
112
}
113
114
Real
UserTimer::lastTime
()
const
115
{
116
return
lasttime
;
117
}
118
119
}
// namespace soplex