~singpolyma/biboumi

ref: 7e64a2e361adcdbd2fce5ad76051a150b4de062d biboumi/src/utils/scopetimer.hpp -rw-r--r-- 558 bytes
7e64a2e3 — louiz’ Add a DEBUG_SQL_QUERIES to log info about the executed SQL queries 5 years ago
                                                                                
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);
                                 });
}