Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
Timer.h
Go to the documentation of this file.
1 //===-- serialbox/core/Timer.h ------------------------------------------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
15 #ifndef SERIALBOX_CORE_TIMER_H
16 #define SERIALBOX_CORE_TIMER_H
17 
18 #include <chrono>
19 
20 namespace serialbox {
21 
24 
26 class Timer {
27 public:
29  Timer() : start_(std::chrono::high_resolution_clock::now()) {}
30 
32  inline void start() noexcept { start_ = std::chrono::high_resolution_clock::now(); }
33 
35  inline double stop() noexcept {
36  auto end = std::chrono::high_resolution_clock::now();
37  return std::chrono::duration<double, std::milli>(end - start_).count();
38  }
39 
40 private:
41  std::chrono::time_point<std::chrono::high_resolution_clock> start_;
42 };
43 
45 
46 } // namespace serialbox
47 
48 #endif
Definition: json.hpp:10517
Namespace of the serialbox library.
Definition: Archive.h:25
void start() noexcept
Reset the timer to the current time.
Definition: Timer.h:32
Timer()
Start the timer.
Definition: Timer.h:29
High resolution timer.
Definition: Timer.h:26
double stop() noexcept
Return the number of milliseconds elapsed since the timer was last reset.
Definition: Timer.h:35