Halide  12.0.1
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;
19  std::string msg;
20 
21  ScopedTimer(const std::string &msg)
22  : start{Clock::now()}, 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;
35 
37  : start{Clock::now()} {
38  }
39 
40  void restart() {
41  start = Clock::now();
42  }
43 
44  std::chrono::duration<double> elapsed() const {
45  return Clock::now() - start;
46  }
47 };
48 
49 } // namespace Autoscheduler
50 } // namespace Internal
51 } // namespace Halide
52 
53 #endif // HL_TIMER_H
std::chrono::high_resolution_clock Clock
Definition: Timer.h:15
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
ScopedTimer(const std::string &msg)
Definition: Timer.h:21
std::chrono::time_point< Clock > start
Definition: Timer.h:18
std::chrono::time_point< Clock > start
Definition: Timer.h:34
std::chrono::duration< double > elapsed() const
Definition: Timer.h:44