Blender V4.3
BLI_timeit.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <chrono>
8#include <string>
9
10#include "BLI_sys_types.h"
11
12namespace blender::timeit {
13
14using Clock = std::chrono::steady_clock;
15using TimePoint = Clock::time_point;
16using Nanoseconds = std::chrono::nanoseconds;
17
18void print_duration(Nanoseconds duration);
19
21 private:
22 std::string name_;
23 TimePoint start_;
24
25 public:
26 ScopedTimer(std::string name) : name_(std::move(name))
27 {
28 start_ = Clock::now();
29 }
30
32};
33
35 private:
36 std::string name_;
37 TimePoint start_;
38
39 int64_t &total_count_;
40 Nanoseconds &total_time_;
41 Nanoseconds &min_time_;
42
43 public:
44 ScopedTimerAveraged(std::string name,
45 int64_t &total_count,
47 Nanoseconds &min_time)
48 : name_(std::move(name)),
49 total_count_(total_count),
50 total_time_(total_time),
51 min_time_(min_time)
52 {
53 start_ = Clock::now();
54 }
55
57};
58
59} // namespace blender::timeit
60
61#define SCOPED_TIMER(name) blender::timeit::ScopedTimer scoped_timer(name)
62
67#define SCOPED_TIMER_AVERAGED(name) \
68 static int64_t total_count_; \
69 static blender::timeit::Nanoseconds total_time_; \
70 static blender::timeit::Nanoseconds min_time_ = blender::timeit::Nanoseconds::max(); \
71 blender::timeit::ScopedTimerAveraged scoped_timer(name, total_count_, total_time_, min_time_)
ScopedTimerAveraged(std::string name, int64_t &total_count, Nanoseconds &total_time, Nanoseconds &min_time)
Definition BLI_timeit.hh:44
ScopedTimer(std::string name)
Definition BLI_timeit.hh:26
std::chrono::nanoseconds Nanoseconds
Definition BLI_timeit.hh:16
Clock::time_point TimePoint
Definition BLI_timeit.hh:15
std::chrono::steady_clock Clock
Definition BLI_timeit.hh:14
void print_duration(Nanoseconds duration)
Definition timeit.cc:42
__int64 int64_t
Definition stdint.h:89
double total_time