Skip to content

Commit 1fcb624

Browse files
Aglargilwangzhengfacontidavide
authored
Refactored the TreeNode::executeTick() function to use a scoped timer for performance monitoring. (#861) (#863)
Update src/tree_node.cpp Co-authored-by: wangzheng <[email protected]> Co-authored-by: Davide Faconti <[email protected]>
1 parent c9dea7b commit 1fcb624

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/tree_node.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,19 @@ NodeStatus TreeNode::executeTick()
106106
if(!substituted)
107107
{
108108
using namespace std::chrono;
109+
109110
auto t1 = steady_clock::now();
111+
// trick to prevent the compile from reordering the order of execution. See #861
112+
// This makes sure that the code is executed at the end of this scope
113+
std::shared_ptr<void> execute_later(nullptr, [&](...) {
114+
auto t2 = steady_clock::now();
115+
if(monitor_tick)
116+
{
117+
monitor_tick(*this, new_status, duration_cast<microseconds>(t2 - t1));
118+
}
119+
});
120+
110121
new_status = tick();
111-
auto t2 = steady_clock::now();
112-
if(monitor_tick)
113-
{
114-
monitor_tick(*this, new_status, duration_cast<microseconds>(t2 - t1));
115-
}
116122
}
117123
}
118124

0 commit comments

Comments
 (0)