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 Feb 9, 2023
1 parent 9fa36fc commit 42e4d74
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/library/time_task.cpp
Expand Up @@ -43,17 +43,21 @@ 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 (g_current_time_task && !m_category.size()) {
// exclude given block from surrounding task
// avoid somewhat costly accesses on `opts`
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 42e4d74

Please sign in to comment.