diff options
author | Hans Goudey <h.goudey@me.com> | 2022-03-24 07:35:23 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-03-24 07:35:23 +0300 |
commit | 7ef3a1a6e6e7495c94076c2dea332aa40ec09db1 (patch) | |
tree | ddbcfbd4196c3e400dd66d96361737a7681e5ab5 /source/blender/blenlib/intern/timeit.cc | |
parent | 610ec34c1f7dbd28f0e3f31b3bb79c52fa97d2cb (diff) |
BLI: Add utility for tacking average and min runtime
This is useful to save time manually averaging many timing results.
The minimum is included because often it can be more stable than an
average, and it can help to expose calls from other contexts with lower
times that would make the average useless.
Differential Revision: https://developer.blender.org/D14417
Diffstat (limited to 'source/blender/blenlib/intern/timeit.cc')
-rw-r--r-- | source/blender/blenlib/intern/timeit.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/timeit.cc b/source/blender/blenlib/intern/timeit.cc index 2dcfe2e6ab1..f11f9c4ad94 100644 --- a/source/blender/blenlib/intern/timeit.cc +++ b/source/blender/blenlib/intern/timeit.cc @@ -2,6 +2,8 @@ #include "BLI_timeit.hh" +#include <algorithm> + namespace blender::timeit { void print_duration(Nanoseconds duration) @@ -17,4 +19,20 @@ void print_duration(Nanoseconds duration) } } +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 |