Skip to content

Commit

Permalink
perf: optimize negative time_task
Browse files Browse the repository at this point in the history
  • Loading branch information
Kha committed Mar 23, 2023
1 parent 8e862e1 commit 1360751
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/library/time_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ void finalize_time_task() {

time_task::time_task(std::string const & category, options const & opts, name decl) :
m_category(category) {
if (get_profiler(opts)) {
if (!m_category.size()) {
// exclude given block from surrounding task, if any
if (g_current_time_task) {
m_timeit = optional<xtimeit>([](second_duration _) {});
m_parent_task = g_current_time_task;
g_current_time_task = this;
}
} else if (get_profiler(opts)) {
m_timeit = optional<xtimeit>(get_profiling_threshold(opts), [=](second_duration duration) mutable {
if (m_category.size()) {
sstream ss;
ss << m_category;
if (decl)
ss << " of " << decl;
ss << " took " << display_profiling_time{duration} << "\n";
// output atomically, like IO.print
tout() << ss.str();
}
sstream ss;
ss << m_category;
if (decl)
ss << " of " << decl;
ss << " took " << display_profiling_time{duration} << "\n";
// output atomically, like IO.print
tout() << ss.str();
});
m_parent_task = g_current_time_task;
g_current_time_task = this;
Expand Down

0 comments on commit 1360751

Please sign in to comment.