Scippy

SoPlex

Sequential object-oriented simPlex

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-2018 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 #include <windows.h>
20 #else
21 #include <sys/times.h>
22 #include <sys/time.h>
23 #endif
24 #include <time.h>
25 
26 #include "soplex/spxdefines.h"
27 #include "soplex/wallclocktimer.h"
28 
29 namespace soplex
30 {
31 
32 // start timer, resume accounting user, system and real time.
34 {
35  // ignore start request if timer is running
36  if (status != RUNNING)
37  {
38 #if !defined(_WIN32) && !defined(_WIN64)
39  struct timeval tp; /*lint !e86*/
40 #endif
41 #if defined(_WIN32) || defined(_WIN64)
42  sec = -::time(NULL);
43 #else
44  gettimeofday(&tp, NULL);
45  if( tp.tv_usec > usec ) /*lint !e115 !e40*/
46  {
47  sec = -(tp.tv_sec + 1); /*lint !e115 !e40*/
48  usec = (1000000 - tp.tv_usec); /*lint !e115 !e40*/
49  }
50  else
51  {
52  sec = -tp.tv_sec; /*lint !e115 !e40*/
53  usec = -tp.tv_usec; /*lint !e115 !e40*/
54  }
55 #endif
56  status = RUNNING;
57  }
58  lasttime = 0.0;
59 }
60 
61 // stop timer, return accounted wallclock time.
63 {
64  // status remains unchanged if timer is not running
65  if (status == RUNNING)
66  {
67 #if !defined(_WIN32) && !defined(_WIN64)
68  struct timeval tp; /*lint !e86*/
69 #endif
70 
71 #if defined(_WIN32) || defined(_WIN64)
72  // we need the blank specifier to distiguish this method from WallclockTimer::time
73  sec += ::time(NULL);
74 #else
75  gettimeofday(&tp, NULL);
76  if( tp.tv_usec + usec > 1000000 ) /*lint !e115 !e40*/
77  {
78  sec += (tp.tv_sec + 1); /*lint !e115 !e40*/
79  usec -= (1000000 - tp.tv_usec); /*lint !e115 !e40*/
80  }
81  else
82  {
83  sec += tp.tv_sec; /*lint !e115 !e40*/
84  usec += tp.tv_usec; /*lint !e115 !e40*/
85  }
86 #endif
87  status = STOPPED;
88  lasttime = wall2sec(sec, usec);
89  }
90  return lasttime;
91 }
92 
93 
95 {
96 #if !defined(_WIN32) && !defined(_WIN64)
97  struct timeval tp; /*lint !e86*/
98 #endif
99  // only update times if timer is still running
100  if( status == RUNNING )
101  {
102 #if defined(_WIN32) || defined(_WIN64)
103  // we need the blank specifier to distiguish this method from WallclockTimer::time
104  lasttime = wall2sec(sec + ::time(NULL), 0);
105 #else
106  gettimeofday(&tp, NULL);
107  // check whether the microseconds add up to more than a second
108  if( tp.tv_usec + usec > 1000000 ) /*lint !e115 !e40*/
109  lasttime = wall2sec(sec + tp.tv_sec + 1, /*lint !e115 !e40*/
110  (usec - 1000000) + tp.tv_usec); /*lint !e115 !e40*/
111  else
112  lasttime = wall2sec(sec + tp.tv_sec, /*lint !e115 !e40*/
113  usec + tp.tv_usec); /*lint !e115 !e40*/
114 #endif
115  }
116  return lasttime;
117 }
118 
120 {
121  return lasttime;
122 }
123 
124 } // namespace soplex
Real wall2sec(long s, long us) const
convert wallclock time to secounds.
long usec
microseconds
virtual Real time() const
virtual Real lastTime() const
WallclockTimer class.
enum soplex::Timer::@2 status
status of the timer
double Real
Definition: spxdefines.h:218
virtual void start()
start timer, resume accounting user, system and real time.
Debugging, floating point type and parameter definitions.
Everything should be within this namespace.
virtual Real stop()
stop timer, return accounted user time.