Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
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
11namespace Halide {
12namespace Internal {
13namespace Autoscheduler {
14
15using Clock = std::chrono::high_resolution_clock;
16
17struct 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
33struct 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
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:42