SheafSystem  0.0.0.0
stop_watch.h
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Interface for class stop_watch
19 
20 #ifndef STOP_WATCH_H
21 #define STOP_WATCH_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef STD_CTIME_H
28 #include "SheafSystem/std_ctime.h"
29 #endif
30 
31 #ifndef STD_IOSTREAM_H
32 #include "SheafSystem/std_iostream.h"
33 #endif
34 
35 #ifndef STD_VECTOR_H
36 #include "SheafSystem/std_vector.h"
37 #endif
38 
39 namespace sheaf
40 {
41 
45 class SHEAF_DLL_SPEC stop_watch
46 {
47 
48 public:
49 
50  // ===========================================================
51  // ANY FACET
52  // ===========================================================
53 
54  // Default memberwise assignment operator
55 
59  virtual bool invariant() const;
60 
61 
62  // ===========================================================
63  // STOP_WATCH FACET
64  // ===========================================================
65 
70  stop_watch();
71 
72  // Default memberwise copy constructor
73 
77  virtual ~stop_watch();
78 
82  enum time_unit
83  {
84  CPU_TIME,
85  MILLISECONDS,
86  SECONDS
87  };
88 
92  void start();
93 
97  void stop();
98 
102  double time(time_unit xunit = SECONDS) const;
103 
108  double cumulative_time() const;
109 
113  void mark_lap();
114 
118  double lap_time(int i) const;
119 
123  size_t lap_ct() const;
124 
128  void reset();
129 
130 
131 private:
132 
136  clock_t _start_time;
137 
141  clock_t _stop_time;
142 
147  double _cumulative_time;
148 
152  std::vector<double> _lap_times;
153 
154 };
155 
156 // ===========================================================
157 // NON-MEMBER FUNCTIONS
158 // ===========================================================
159 
163 SHEAF_DLL_SPEC
164 std::ostream&
165 operator << (std::ostream &os, stop_watch& xsw);
166 
167 } // namespace sheaf
168 
169 #endif // ifndef STOP_WATCH_H
time_unit
The unit of time to return.
Definition: stop_watch.h:82
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
Namespace for the sheaves component of the sheaf system.
A clock for timing intervals.
Definition: stop_watch.h:45