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