Motorcortex Core  version: 2.7.6
utl_chrono.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2015 VECTIONEER.
4  */
5 
6 #ifndef UTILS_UTL_CHRONO_H_
7 #define UTILS_UTL_CHRONO_H_
8 
9 #include <chrono>
10 #include <utility>
11 
12 namespace mcx {
13 
14 namespace utils {
15 
16 template <typename TimeT = std::chrono::milliseconds>
17 struct measure {
18  template <typename F, typename... Args>
19  static typename TimeT::rep execution(F&& func, Args&&... args) {
20  auto start = std::chrono::system_clock::now();
21  std::forward<decltype(func)>(func)(std::forward<Args>(args)...);
22  auto duration = std::chrono::duration_cast<TimeT>(std::chrono::system_clock::now() - start);
23  return duration.count();
24  }
25 
26  static void start(void) { start_time_ = std::chrono::system_clock::now(); }
27 
28  static typename TimeT::rep stop(void) {
29  auto duration = std::chrono::duration_cast<TimeT>(std::chrono::system_clock::now() - start_time_);
30  return duration.count();
31  }
32 
33  static std::chrono::system_clock::time_point start_time_;
34 };
35 
36 template <typename TimeT>
37 std::chrono::system_clock::time_point measure<TimeT>::start_time_;
38 
39 } // namespace utils
40 
41 } // namespace mcx
42 
43 #endif // UTILS_UTL_CHRONO_H_
mcx::utils::measure
Definition: utl_chrono.h:17