diff options
Diffstat (limited to 'source/blender/blenlib/BLI_timeit.hh')
-rw-r--r-- | source/blender/blenlib/BLI_timeit.hh | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_timeit.hh b/source/blender/blenlib/BLI_timeit.hh index 31e1b5d2a03..2c89c8dd7ac 100644 --- a/source/blender/blenlib/BLI_timeit.hh +++ b/source/blender/blenlib/BLI_timeit.hh @@ -38,6 +38,41 @@ class ScopedTimer { } }; +class ScopedTimerAveraged { + private: + std::string name_; + TimePoint start_; + + int64_t &total_count_; + Nanoseconds &total_time_; + Nanoseconds &min_time_; + + public: + ScopedTimerAveraged(std::string name, + int64_t &total_count, + Nanoseconds &total_time, + Nanoseconds &min_time) + : name_(std::move(name)), + total_count_(total_count), + total_time_(total_time), + min_time_(min_time) + { + start_ = Clock::now(); + } + + ~ScopedTimerAveraged(); +}; + } // namespace blender::timeit #define SCOPED_TIMER(name) blender::timeit::ScopedTimer scoped_timer(name) + +/** + * Print the average and minumum runtime of the timer's scope. + * \warning This uses static variables, so it is not thread-safe. + */ +#define SCOPED_TIMER_AVERAGED(name) \ + static int64_t total_count_; \ + static blender::timeit::Nanoseconds total_time_; \ + static blender::timeit::Nanoseconds min_time_ = blender::timeit::Nanoseconds::max(); \ + blender::timeit::ScopedTimerAveraged scoped_timer(name, total_count_, total_time_, min_time_) |