24 lines
615 B
C++
24 lines
615 B
C++
#pragma once
|
|
#include <chrono>
|
|
|
|
#include "spdlog/spdlog.h"
|
|
|
|
class query_timer {
|
|
public:
|
|
query_timer(std::string name) : name_(std::move(name)) {
|
|
start();
|
|
}
|
|
~query_timer() {
|
|
const auto end = std::chrono::high_resolution_clock::now();
|
|
const auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start_);
|
|
spdlog::info("{}: {} ms", name_, duration.count() / 1000.f);
|
|
}
|
|
|
|
private:
|
|
void start() {
|
|
start_ = std::chrono::high_resolution_clock::now();
|
|
}
|
|
std::chrono::high_resolution_clock::time_point start_;
|
|
std::string name_;
|
|
};
|