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 static_cast<float>(
27  std::chrono::duration_cast<ns>(clock::now() - start_time_).count());
28  }
32  inline float MilliSeconds() { return NanoSeconds() / 1000000.f; }
36  inline float MicroSeconds() { return NanoSeconds() / 1000.f; }
40  inline float Seconds() { return NanoSeconds() / 1000000000.f; }
41 
42  protected:
43  std::chrono::time_point<clock> start_time_;
44  C10_DISABLE_COPY_AND_ASSIGN(Timer);
45 };
46 }
47 
48 #endif // CAFFE2_CORE_TIMER_H_
void Start()
Starts a timer.
Definition: timer.h:24
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
float MilliSeconds()
Returns the elapsed time in milliseconds.
Definition: timer.h:32
float Seconds()
Returns the elapsed time in seconds.
Definition: timer.h:40
float MicroSeconds()
Returns the elapsed time in microseconds.
Definition: timer.h:36
A simple timer object for measuring time.
Definition: timer.h:16