Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TimeMeasurement.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef _TIMEMEASUREMENT_H_
27 #define _TIMEMEASUREMENT_H_
28 
29 #include <bias_config.h>
30 #include <string>
31 #include <iostream>
32 #include <Base/Debug/TimeMeasure.hh>
33 
34 /** @ingroup g_utils
35 @file TimeMeasurement.hh
36 @brief Time measurement based on instance construction and destruction
37 
38 Usage:
39 \verbatim:
40 // -- previous other code ...
41 {
42  // -- more previous other code ...
43  // construct an instance as "Start" function:
44  BIAS::TimeMeasurement timerInstance("my optional description");
45  // >> code to be timed here, e.g.:
46  sleep(1000);
47  // <<
48 } // Stop by automatic destruction of instance
49  // due to end of scope at closing bracket
50 // -- later other code -- ...
51 \endverbatim
52 @author Jan Woetzel */
53 namespace BIAS {
55  {
56  public:
57  /// destructor working as STOP function
59  timer_.Stop();
60  if (this->description_.size()>0)
61  std::cout<<"TimeMeasurement "<<this->description_<<" :"<<std::endl;
62  timer_.Print();
63  }
64 
65  /// constructor working as START function
67  {
68  Start();
69  }
70 
71  /// constructor with additional description
72  TimeMeasurement(const std::string & str){
73  description_ = str;
74  Start();
75  }
76 
77  /** @brief Reset and Start the timer
78 
79  Useful for earlier construction
80  @author Jan Woetzel */
81  void Start(){
82  timer_.Reset();
83  timer_.Start();
84  }
85 
86  protected:
87  /// local timer used by ctor and detor
89  std::string description_;
90  }; // end of class TimeMeasurement
91 } // end of namespace
92 
93 
94 #endif // _TIMEMEASUREMENT_H_
95 
void Print(std::ostream &os=std::cout) const
TimeMeasurement()
constructor working as START function
void Start()
Reset and Start the timer.
~TimeMeasurement()
destructor working as STOP function
TimeMeasurement(const std::string &str)
constructor with additional description
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111
BIAS::TimeMeasure timer_
local timer used by ctor and detor