From 1fcb624d4d7b9d1f357378b20ff19bdcc3853cea Mon Sep 17 00:00:00 2001 From: Aglargil <34728006+Aglargil@users.noreply.github.com> Date: Sat, 21 Sep 2024 18:40:19 +0800 Subject: [PATCH] Refactored the TreeNode::executeTick() function to use a scoped timer for performance monitoring. (#861) (#863) Update src/tree_node.cpp Co-authored-by: wangzheng Co-authored-by: Davide Faconti --- src/tree_node.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tree_node.cpp b/src/tree_node.cpp index 0351f76e7..7b7a4ac88 100644 --- a/src/tree_node.cpp +++ b/src/tree_node.cpp @@ -106,13 +106,19 @@ NodeStatus TreeNode::executeTick() if(!substituted) { using namespace std::chrono; + auto t1 = steady_clock::now(); + // trick to prevent the compile from reordering the order of execution. See #861 + // This makes sure that the code is executed at the end of this scope + std::shared_ptr execute_later(nullptr, [&](...) { + auto t2 = steady_clock::now(); + if(monitor_tick) + { + monitor_tick(*this, new_status, duration_cast(t2 - t1)); + } + }); + new_status = tick(); - auto t2 = steady_clock::now(); - if(monitor_tick) - { - monitor_tick(*this, new_status, duration_cast(t2 - t1)); - } } }