Luanti
5.11.0-dev
Loading...
Searching...
No Matches
timetaker.h
Go to the documentation of this file.
1
// Luanti
2
// SPDX-License-Identifier: LGPL-2.1-or-later
3
// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5
#pragma once
6
7
#include <string>
8
#include "
irrlichttypes.h
"
9
10
enum
TimePrecision
: s8
11
{
12
PRECISION_SECONDS
,
13
PRECISION_MILLI
,
14
PRECISION_MICRO
,
15
PRECISION_NANO
,
16
};
17
18
constexpr
const
char
*
TimePrecision_units
[] = {
19
"s"
/* PRECISION_SECONDS */
,
20
"ms"
/* PRECISION_MILLI */
,
21
"us"
/* PRECISION_MICRO */
,
22
"ns"
/* PRECISION_NANO */
,
23
};
24
25
/*
26
TimeTaker
27
*/
28
29
// Note: this class should be kept lightweight
30
31
class
TimeTaker
32
{
33
public
:
34
TimeTaker
(
const
std::string &name, u64 *result =
nullptr
,
35
TimePrecision
prec =
PRECISION_MILLI
)
36
{
37
if
(result)
38
m_result
= result;
39
else
40
m_name
= name;
41
m_precision
= prec;
42
start
();
43
}
44
45
~TimeTaker
()
46
{
47
stop
();
48
}
49
50
u64
stop
(
bool
quiet=
false
);
51
52
u64
getTimerTime
();
53
54
private
:
55
void
start
();
56
57
std::string
m_name
;
58
u64 *
m_result
=
nullptr
;
59
u64
m_time1
;
60
bool
m_running
=
true
;
61
TimePrecision
m_precision
;
62
};
TimeTaker
Definition
timetaker.h:32
TimeTaker::TimeTaker
TimeTaker(const std::string &name, u64 *result=nullptr, TimePrecision prec=PRECISION_MILLI)
Definition
timetaker.h:34
TimeTaker::start
void start()
Definition
timetaker.cpp:11
TimeTaker::stop
u64 stop(bool quiet=false)
Definition
timetaker.cpp:16
TimeTaker::m_precision
TimePrecision m_precision
Definition
timetaker.h:61
TimeTaker::m_result
u64 * m_result
Definition
timetaker.h:58
TimeTaker::m_name
std::string m_name
Definition
timetaker.h:57
TimeTaker::m_running
bool m_running
Definition
timetaker.h:60
TimeTaker::~TimeTaker
~TimeTaker()
Definition
timetaker.h:45
TimeTaker::m_time1
u64 m_time1
Definition
timetaker.h:59
TimeTaker::getTimerTime
u64 getTimerTime()
Definition
timetaker.cpp:34
irrlichttypes.h
TimePrecision_units
constexpr const char * TimePrecision_units[]
Definition
timetaker.h:18
TimePrecision
TimePrecision
Definition
timetaker.h:11
PRECISION_SECONDS
@ PRECISION_SECONDS
Definition
timetaker.h:12
PRECISION_NANO
@ PRECISION_NANO
Definition
timetaker.h:15
PRECISION_MICRO
@ PRECISION_MICRO
Definition
timetaker.h:14
PRECISION_MILLI
@ PRECISION_MILLI
Definition
timetaker.h:13
util
timetaker.h
Generated on Sun Dec 1 2024 10:42:57 for Luanti by
1.11.0