LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
timer.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "timer.h"
10 #include <QtDebug>
11 
12 namespace LC::Util
13 {
14  Timer::Timer (std::string_view label, Resolution resolution)
15  : Label_ { label }
16  , Resolution_ { resolution }
17  {
18  Timer_.start ();
19  }
20 
22  {
23  auto diff = Timer_.nsecsElapsed ();
24 
25  const char *unit = nullptr;
26  switch (Resolution_)
27  {
28  case Resolution::ns:
29  unit = "ns";
30  break;
31  case Resolution::us:
32  diff /= 1e3;
33  unit = "us";
34  break;
35  case Resolution::ms:
36  diff /= 1e6;
37  unit = "ms";
38  break;
39  }
40 
41  qDebug () << Label_.data () // TODO Qt6: no need for data() here
42  << "took"
43  << diff
44  << unit;
45  }
46 }