blob: f11f9c4ad944bc57cbbe3e80d8df224b9be25e07 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_timeit.hh"
#include <algorithm>
namespace blender::timeit {
void print_duration(Nanoseconds duration)
{
if (duration < std::chrono::microseconds(100)) {
std::cout << duration.count() << " ns";
}
else if (duration < std::chrono::seconds(5)) {
std::cout << duration.count() / 1.0e6 << " ms";
}
else {
std::cout << duration.count() / 1.0e9 << " s";
}
}
ScopedTimerAveraged::~ScopedTimerAveraged()
{
const TimePoint end = Clock::now();
const Nanoseconds duration = end - start_;
total_count_++;
total_time_ += duration;
min_time_ = std::min(duration, min_time_);
std::cout << "Timer '" << name_ << "': (Average: ";
print_duration(total_time_ / total_count_);
std::cout << ", Min: ";
print_duration(min_time_);
std::cout << ")\n";
}
} // namespace blender::timeit
|