Caffe2 - C++ API
A deep learning, cross platform ML framework
timer.h
1 
17 #ifndef CAFFE2_CORE_TIMER_H_
18 #define CAFFE2_CORE_TIMER_H_
19 
20 #include <chrono>
21 
22 #include "caffe2/core/common.h"
23 
24 namespace caffe2 {
25 
32 class Timer {
33  public:
34  typedef std::chrono::high_resolution_clock clock;
35  typedef std::chrono::nanoseconds ns;
36  Timer() { Start(); }
40  inline void Start() { start_time_ = clock::now(); }
41  inline float NanoSeconds() {
42  return static_cast<float>(
43  std::chrono::duration_cast<ns>(clock::now() - start_time_).count());
44  }
48  inline float MilliSeconds() { return NanoSeconds() / 1000000.f; }
52  inline float MicroSeconds() { return NanoSeconds() / 1000.f; }
56  inline float Seconds() { return NanoSeconds() / 1000000000.f; }
57 
58  protected:
59  std::chrono::time_point<clock> start_time_;
60  DISABLE_COPY_AND_ASSIGN(Timer);
61 };
62 }
63 
64 #endif // CAFFE2_CORE_TIMER_H_
void Start()
Starts a timer.
Definition: timer.h:40
Copyright (c) 2016-present, Facebook, Inc.
float MilliSeconds()
Returns the elapsed time in milliseconds.
Definition: timer.h:48
float Seconds()
Returns the elapsed time in seconds.
Definition: timer.h:56
float MicroSeconds()
Returns the elapsed time in microseconds.
Definition: timer.h:52
A simple timer object for measuring time.
Definition: timer.h:32