DDS  ver. 3.4
TimeMeasure.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 // This file contains a number of helpers to calculate execution time of a function.
4 //
5 #ifndef TIMEMEASURE_H_
6 #define TIMEMEASURE_H_
7 
8 #include <chrono>
9 
10 namespace MiscCommon
11 {
12  template <typename TimeT = std::chrono::milliseconds>
13  struct STimeMeasure
14  {
15  template <typename F, typename... Args>
16  static typename TimeT::rep execution(F func, Args&&... args)
17  {
18  auto start = std::chrono::system_clock::now();
19 
20  // Now call the function with all the parameters you need.
21  func(std::forward<Args>(args)...);
22 
23  auto duration = std::chrono::duration_cast<TimeT>(std::chrono::system_clock::now() - start);
24 
25  return duration.count();
26  }
27 
28  // template <typename F>
29  // static typename TimeT::rep execution(F const& func)
30  // {
31  // auto start = std::chrono::system_clock::now();
32  // func();
33  // auto duration = std::chrono::duration_cast<TimeT>(std::chrono::system_clock::now() - start);
34  // return duration.count();
35  // }
36  };
37 } // namespace MiscCommon
38 
39 #endif /*TIMEMEASURE_H_*/
Definition: TimeMeasure.h:13
static TimeT::rep execution(F func, Args &&... args)
Definition: TimeMeasure.h:16
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21