CUV  0.9.201304091348
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
timing.hpp
1 //*LB*
2 // Copyright (c) 2010, University of Bonn, Institute for Computer Science VI
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the University of Bonn
14 // nor the names of its contributors may be used to endorse or promote
15 // products derived from this software without specific prior written
16 // permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //*LE*
29 
30 
31 
32 
33 
34 #ifndef __AIS_TIMING_HPP__
35 #define __AIS_TIMING_HPP__
36 
37 #include <boost/date_time/posix_time/posix_time_types.hpp>
38 
53 class Timing
54 {
55  public:
61  inline Timing();
62 
68  inline double diff() const;
77  inline double perf() ;
83  inline int count() const;
90  inline void update(int inc=1);
96  inline void reset();
97 
98  private:
99  boost::posix_time::ptime m_start;
100  boost::posix_time::ptime m_end;
101  int m_count;
102 
103 };
104 
106  : m_start(boost::posix_time::microsec_clock::universal_time())
107  , m_end(boost::posix_time::microsec_clock::universal_time())
108  , m_count(0)
109 {}
110 
111 inline double Timing::diff() const
112 {
113  return (m_end - m_start).total_microseconds() / (double)1e6;
114 }
115 
116 inline void Timing::update(int inc)
117 {
118  m_end = boost::posix_time::microsec_clock::universal_time();
119  m_count += inc;
120 }
121 
122 inline double Timing::perf()
123 {
124  if(m_count==0)
125  update(1);
126  return diff() / m_count ;
127 }
128 
130 {
131  m_start = boost::posix_time::microsec_clock::universal_time();
132  m_end = boost::posix_time::microsec_clock::universal_time();
133  m_count = 0;
134 }
135 
136 inline int Timing::count() const
137 {
138  return m_count;
139 } // end group tools
141 
142 #endif /* __AIS_TIMING_HPP__ */