Caffe2 - C++ API
A deep learning, cross platform ML framework
timer.h
1 #ifndef CAFFE2_CORE_TIMER_H_
2 #define CAFFE2_CORE_TIMER_H_
3 
4 #include <chrono>
5 
6 #include "caffe2/core/common.h"
7 
8 namespace caffe2 {
9 
16 class Timer {
17  public:
18  typedef std::chrono::high_resolution_clock clock;
19  typedef std::chrono::nanoseconds ns;
20  Timer() { Start(); }
24  inline void Start() { start_time_ = clock::now(); }
25  inline float NanoSeconds() {
26  return std::chrono::duration_cast<ns>(clock::now() - start_time_).count();
27  }
31  inline float MilliSeconds() { return NanoSeconds() / 1000000.f; }
35  inline float MicroSeconds() { return NanoSeconds() / 1000.f; }
39  inline float Seconds() { return NanoSeconds() / 1000000000.f; }
40 
41  protected:
42  std::chrono::time_point<clock> start_time_;
43  DISABLE_COPY_AND_ASSIGN(Timer);
44 };
45 }
46 
47 #endif // CAFFE2_CORE_TIMER_H_
float Seconds()
Returns the elapsed time in seconds.
Definition: timer.h:39
float MilliSeconds()
Returns the elapsed time in milliseconds.
Definition: timer.h:31
float MicroSeconds()
Returns the elapsed time in microseconds.
Definition: timer.h:35
A simple timer object for measuring time.
Definition: timer.h:16
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
void Start()
Starts a timer.
Definition: timer.h:24