SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
cpu_timer.h
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
29 #ifndef CPU_TIMER_HEADER_GUARD
30 #define CPU_TIMER_HEADER_GUARD
31 
32 //include boost libraries
33 //#define BOOST_LIB_DIAGNOSTIC
34 //let the library have dependencies for now
35 //#define BOOST_CHRONO_HEADER_ONLY
36 //#define BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING//required in order to avoid dependency on Boost.System
37 #include "boost/timer/timer.hpp"
38 
39 //include C++ headers
40 #include <sstream>
41 
42 namespace SeComLib {
43 namespace Utils {
47  class CpuTimer {
48  public:
50  typedef boost::timer::nanosecond_type NanosecondType;
51 
53  CpuTimer ();
54 
56  ~CpuTimer () {}
57 
59  void Stop ();
60 
62  void Reset ();
63 
65  NanosecondType GetDuration () const;
66 
68  std::string ToString () const;
69 
71  static std::string ToString (CpuTimer::NanosecondType userTime);
72 
73  private:
75  boost::timer::cpu_timer timer;
76 
78  CpuTimer (CpuTimer const &);
79 
81  CpuTimer operator= (CpuTimer const &);
82  };
83 
84 }//namespace Utils
85 }//namespace SeComLib
86 
87 #endif//CPU_TIMER_HEADER_GUARD
~CpuTimer()
Destructor - void implementation.
Definition: cpu_timer.h:56
boost::timer::nanosecond_type NanosecondType
Nanosecond data type (int_least64_t)
Definition: cpu_timer.h:50
Utilitary class providing algorithm timing functionality.
Definition: cpu_timer.h:47
std::string ToString() const
Returns the elapsed user process time as a formatted string (HH::MM::SS.mmm)
Definition: cpu_timer.cpp:63
void Stop()
Stops the timer.
Definition: cpu_timer.cpp:43
boost::timer::cpu_timer timer
the internal timer variable
Definition: cpu_timer.h:75
CpuTimer operator=(CpuTimer const &)
Copy assignment operator - not implemented.
CpuTimer()
Default constructor.
Definition: cpu_timer.cpp:37
NanosecondType GetDuration() const
Returns the elapsed user process time (in nanoseconds)
Definition: cpu_timer.cpp:56
void Reset()
Resets the timer.
Definition: cpu_timer.cpp:49