[Bf-blender-cvs] [41f83ef5711] functions: scoped timer per element
Jacques Lucke
noreply at git.blender.org
Mon Jul 29 17:57:04 CEST 2019
Commit: 41f83ef5711f2ccead6d799d7b8a9e5a187a9d33
Author: Jacques Lucke
Date: Mon Jul 29 10:03:27 2019 +0200
Branches: functions
https://developer.blender.org/rB41f83ef5711f2ccead6d799d7b8a9e5a187a9d33
scoped timer per element
===================================================================
M source/blender/blenlib/BLI_timeit.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_timeit.hpp b/source/blender/blenlib/BLI_timeit.hpp
index dfb4ee9a0da..ae3d5204a41 100644
--- a/source/blender/blenlib/BLI_timeit.hpp
+++ b/source/blender/blenlib/BLI_timeit.hpp
@@ -94,6 +94,35 @@ class ScopedTimerStatistics {
}
};
+class ScopedTimerPerElement {
+ private:
+ TimePoint m_start;
+ const char *m_name;
+ uint m_element_amount;
+
+ public:
+ ScopedTimerPerElement(const char *name, uint element_amount)
+ : m_name(name), m_element_amount(element_amount)
+ {
+ m_start = Clock::now();
+ }
+
+ ~ScopedTimerPerElement()
+ {
+ TimePoint end = Clock::now();
+
+ if (m_element_amount == 0) {
+ return;
+ }
+
+ Nanoseconds duration = end - m_start;
+ Nanoseconds duration_per_element = duration / m_element_amount;
+ std::cout << "Timer '" << m_name << "' per element (" << m_element_amount << " elements): ";
+ print_duration(duration_per_element);
+ std::cout << '\n';
+ }
+};
+
} // namespace Timers
}; // namespace BLI
@@ -105,3 +134,5 @@ class ScopedTimerStatistics {
static BLI::Timers::Nanoseconds shortest_duration = std::chrono::seconds(100); \
static BLI::Timers::Nanoseconds timings_sum(0); \
BLI::Timers::ScopedTimerStatistics t(name, shortest_duration, timings_sum, timings_done);
+
+#define SCOPED_TIMER_ELEMENT(name, elements) BLI::Timers::ScopedTimerPerElement t(name, elements);
More information about the Bf-blender-cvs
mailing list