SoPlex
Toggle main menu visibility
Loading...
Searching...
No Matches
src
soplex
wallclocktimer.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
#include <windows.h>
29
#else
30
#include <sys/times.h>
31
#include <sys/time.h>
32
#endif
33
#include <time.h>
34
35
#include "
soplex/spxdefines.h
"
36
#include "
soplex/wallclocktimer.h
"
37
38
namespace
soplex
39
{
40
41
// start timer, resume accounting user, system and real time.
42
void
WallclockTimer::start
()
43
{
44
// ignore start request if timer is running
45
if
(
status
!=
RUNNING
)
46
{
47
#ifdef _WIN32
48
sec
= -
::time
(
nullptr
);
49
#else
50
struct
timeval tp;
/*lint !e86*/
51
52
gettimeofday(&tp,
nullptr
);
53
54
if
(tp.tv_usec >
usec
)
/*lint !e115 !e40*/
55
{
56
sec
= -(tp.tv_sec + 1);
/*lint !e115 !e40*/
57
usec
= (1000000 - tp.tv_usec);
/*lint !e115 !e40*/
58
}
59
else
60
{
61
sec
= -tp.tv_sec;
/*lint !e115 !e40*/
62
usec
= -tp.tv_usec;
/*lint !e115 !e40*/
63
}
64
65
#endif
66
67
status
=
RUNNING
;
68
}
69
70
lasttime
= 0.0;
71
}
72
73
// stop timer, return accounted wallclock time.
74
Real
WallclockTimer::stop
()
75
{
76
// status remains unchanged if timer is not running
77
if
(
status
==
RUNNING
)
78
{
79
#ifdef _WIN32
80
// we need the blank specifier to distiguish this method from WallclockTimer::time
81
sec
+=
::time
(
nullptr
);
82
#else
83
struct
timeval tp;
/*lint !e86*/
84
85
gettimeofday(&tp,
nullptr
);
86
87
if
(tp.tv_usec +
usec
> 1000000)
/*lint !e115 !e40*/
88
{
89
sec
+= (tp.tv_sec + 1);
/*lint !e115 !e40*/
90
usec
-= (1000000 - tp.tv_usec);
/*lint !e115 !e40*/
91
}
92
else
93
{
94
sec
+= tp.tv_sec;
/*lint !e115 !e40*/
95
usec
+= tp.tv_usec;
/*lint !e115 !e40*/
96
}
97
98
#endif
99
100
status
=
STOPPED
;
101
lasttime
=
wall2sec
(
sec
,
usec
);
102
}
103
104
return
lasttime
;
105
}
106
107
108
Real
WallclockTimer::time
()
const
109
{
110
// only update times if timer is still running
111
if
(
status
==
RUNNING
)
112
{
113
#ifdef _WIN32
114
// we need the blank specifier to distiguish this method from WallclockTimer::time
115
lasttime
=
wall2sec
(
sec
+
::time
(
nullptr
), 0);
116
#else
117
struct
timeval tp;
/*lint !e86*/
118
119
gettimeofday(&tp,
nullptr
);
120
121
// check whether the microseconds add up to more than a second
122
if
(tp.tv_usec +
usec
> 1000000)
/*lint !e115 !e40*/
123
lasttime
=
wall2sec
(
sec
+ tp.tv_sec + 1,
/*lint !e115 !e40*/
124
(
usec
- 1000000) + tp.tv_usec);
/*lint !e115 !e40*/
125
else
126
lasttime
=
wall2sec
(
sec
+ tp.tv_sec,
/*lint !e115 !e40*/
127
usec
+ tp.tv_usec);
/*lint !e115 !e40*/
128
129
#endif
130
}
131
132
return
lasttime
;
133
}
134
135
Real
WallclockTimer::lastTime
()
const
136
{
137
return
lasttime
;
138
}
139
140
}
// 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::WallclockTimer::sec
time_t sec
seconds
Definition
wallclocktimer.h:45
soplex::WallclockTimer::stop
virtual Real stop()
stop timer, return accounted user time.
Definition
wallclocktimer.cpp:74
soplex::WallclockTimer::lastTime
virtual Real lastTime() const
Definition
wallclocktimer.cpp:135
soplex::WallclockTimer::start
virtual void start()
start timer, resume accounting user, system and real time.
Definition
wallclocktimer.cpp:42
soplex::WallclockTimer::lasttime
Real lasttime
Definition
wallclocktimer.h:48
soplex::WallclockTimer::time
virtual Real time() const
Definition
wallclocktimer.cpp:108
soplex::WallclockTimer::wall2sec
Real wall2sec(time_t s, time_t us) const
convert wallclock time to secounds.
Definition
wallclocktimer.h:55
soplex::WallclockTimer::usec
time_t usec
microseconds
Definition
wallclocktimer.h:46
soplex
Everything should be within this namespace.
soplex::Real
double Real
Definition
spxdefines.h:269
spxdefines.h
Debugging, floating point type and parameter definitions.
wallclocktimer.h
WallclockTimer class.
Generated by
1.17.0