summaryrefslogtreecommitdiff
path: root/src/utils/scopetimer.hpp
blob: 7d3db9b8a6e380d014c55432dff59659b7eb2562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <utils/scopeguard.hpp>

#include <chrono>

#include <logger/logger.hpp>

template <typename Callback>
auto make_scope_timer(Callback cb)
{
  const auto start_time = std::chrono::steady_clock::now();
  return utils::make_scope_guard([start_time, cb = std::move(cb)]()
                                 {
                                   const auto now = std::chrono::steady_clock::now();
                                   const auto elapsed = now - start_time;
                                   cb(elapsed);
                                 });
}