Albert
Loading...
Searching...
No Matches
timeit.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Manuel Schneider
2
3#pragma once
4#include <QDebug>
5#include <QString>
6#include <chrono>
7#include <albert/logging.h>
8
9// Private API
10namespace albert::detail
11{
12
13struct TimeIt
14{
15 QString name_;
16 std::chrono::system_clock::time_point start_;
17
18 [[nodiscard]] TimeIt(const QString &name = {}):
19 name_(name),
20 start_(std::chrono::system_clock::now())
21 {}
22
23 ~TimeIt()
24 {
25 auto end = std::chrono::system_clock::now();
26 auto dur = std::chrono::duration_cast<std::chrono::microseconds>(end - start_).count();
27 CRIT << QStringLiteral("\x1b[36m%L1 µs | %2").arg(dur, 8).arg(name_);
28 }
29};
30
31}
#define CRIT
Creates a log object (level critial) you can use to pipe text into (<<).
Definition logging.h:32