iRoCS Toolbox  1.1.0
ATBTiming.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 /*======================================================================*/
29 /*======================================================================*/
30 
31 #ifndef ATBTIMING_HH
32 #define ATBTIMING_HH
33 
34 #ifdef HAVE_CONFIG_H
35 #include <config.hh>
36 #endif
37 
38 #include <string>
39 #include <iostream>
40 
41 namespace atb
42 {
43 
44 /*======================================================================*/
54 /*======================================================================*/
55  struct MyDateTime
56  {
57 
58 /*======================================================================*/
66 /*======================================================================*/
67  static std::string prettyTime();
68 
69 /*======================================================================*/
75 /*======================================================================*/
76  static long long time_us();
77 
78 /*======================================================================*/
84 /*======================================================================*/
85  static std::string prettyDate();
86 
87 /*======================================================================*/
94 /*======================================================================*/
95  static std::string prettyTime(long long time_us);
96 
97  };
98 
99 
100 /*======================================================================*/
111 /*======================================================================*/
112  class Timer
113  {
114 
115  public:
116 
117 /*======================================================================*/
124 /*======================================================================*/
125  Timer(std::ostream &outStream = std::cout);
126 
127 /*======================================================================*/
131 /*======================================================================*/
132  ~Timer();
133 
134 /*======================================================================*/
141 /*======================================================================*/
142  void tic(const std::string& output = "");
143 
144 /*======================================================================*/
153 /*======================================================================*/
154  long long toc();
155 
156  private:
157 
158  long long _startTime;
159  bool _running;
160  std::ostream& _outStream;
161 
162  };
163 
164 /*======================================================================*/
175 /*======================================================================*/
176  class Profiler
177  {
178 
179  public:
180 
181 /*======================================================================*/
185 /*======================================================================*/
186  Profiler();
187 
188 /*======================================================================*/
192 /*======================================================================*/
193  ~Profiler();
194 
195 /*======================================================================*/
199 /*======================================================================*/
200  void tic();
201 
202 /*======================================================================*/
208 /*======================================================================*/
209  long long toc();
210 
211  private:
212 
213  long long _startTime;
214  bool _running;
215 
216  };
217 
218 }
219 
220 #endif
The MyDateTime struct provides pretty printed date - time strings with microsecond resolution...
Definition: ATBTiming.hh:55
static std::string prettyDate()
Get a pretty printed version of the current system date and time.
static long long time_us()
Get the elapsed microseconds since system boot.
static std::string prettyTime()
Timestamp relative to system boot in microsecond accuracy of the form xxxxxxxxxxxx.xxxxxx (s.mus).
The Profiler class provides a simple stop-watch in microsecond accuracy for simple profiling tasks (s...
Definition: ATBTiming.hh:176
The Timer class provides a simple stop-watch in microsecond accuracy for simple profiling tasks (simi...
Definition: ATBTiming.hh:112