Halide  17.0.2
Halide compiler and libraries
Timer.h
Go to the documentation of this file.
1 #ifndef HL_TIMER_H
2 #define HL_TIMER_H
3 
4 #include <chrono>
5 #include <set>
6 #include <string>
7 #include <vector>
8 
9 #include "ASLog.h"
10 
11 namespace Halide {
12 namespace Internal {
13 namespace Autoscheduler {
14 
15 using Clock = std::chrono::high_resolution_clock;
16 
17 struct ScopedTimer {
18  std::chrono::time_point<Clock> start = Clock::now();
19  std::string msg;
20 
21  explicit ScopedTimer(const std::string &msg)
22  : msg{msg} {
23  aslog(0) << "Start: " << msg << "\n";
24  }
25 
27  auto duration = Clock::now() - start;
28  auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
29  aslog(0) << "Duration (ms): " << msg << " = " << ms << "\n";
30  }
31 };
32 
33 struct Timer {
34  std::chrono::time_point<Clock> start = Clock::now();
35 
36  Timer() = default;
37 
38  void restart() {
39  start = Clock::now();
40  }
41 
42  std::chrono::duration<double> elapsed() const {
43  return Clock::now() - start;
44  }
45 };
46 
47 } // namespace Autoscheduler
48 } // namespace Internal
49 } // namespace Halide
50 
51 #endif // HL_TIMER_H
std::chrono::high_resolution_clock Clock
Definition: Timer.h:15
std::chrono::time_point< Clock > start
Definition: Timer.h:34
std::chrono::time_point< Clock > start
Definition: Timer.h:18
This file defines the class FunctionDAG, which is our representation of a Halide pipeline, and contains methods to using Halide&#39;s bounds tools to query properties of it.
std::chrono::duration< double > elapsed() const
Definition: Timer.h:42
ScopedTimer(const std::string &msg)
Definition: Timer.h:21
Not visible externally, similar to &#39;static&#39; linkage in C.