UFJF - Machine Learning Toolkit  0.51.8
Timer.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <cstdio>
9 #include <ctime>
10 #include <chrono>
11 
12 namespace mltk{
16  class Timer {
17  private:
18  using Clock = std::chrono::high_resolution_clock;
19  typename Clock::time_point start_point;
20  public:
24  inline Timer() : start_point(Clock::now()) {}
28  inline void reset(){ start_point = Clock::now(); }
33  template <typename Rep = double, typename Units = typename std::chrono::milliseconds>
34  inline double elapsed() const {
35  std::atomic_thread_fence(std::memory_order_relaxed);
36  auto counted_time = std::chrono::duration_cast<Units>(Clock::now() - start_point).count();
37  std::atomic_thread_fence(std::memory_order_relaxed);
38  return static_cast<Rep>(counted_time);
39  }
40  };
41 }
Wrapper for the implementation of a simple timer.
Definition: Timer.hpp:16
Timer()
Contructor already initiate the timer to the current time.
Definition: Timer.hpp:24
void reset()
Set the timer to the current time.
Definition: Timer.hpp:28
double elapsed() const
Returns the elapsed time.
Definition: Timer.hpp:34
UFJF-MLTK main namespace for core functionalities.
Definition: classifier/Classifier.hpp:11