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
17
18constexpr 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
32{
33public:
34 TimeTaker(const std::string &name, u64 *result = nullptr,
36 {
37 if (result)
38 m_result = result;
39 else
40 m_name = name;
41 m_precision = prec;
42 start();
43 }
44
46 {
47 stop();
48 }
49
50 u64 stop(bool quiet=false);
51
52 u64 getTimerTime();
53
54private:
55 void start();
56
57 std::string m_name;
58 u64 *m_result = nullptr;
60 bool m_running = true;
62};
Definition timetaker.h:32
TimeTaker(const std::string &name, u64 *result=nullptr, TimePrecision prec=PRECISION_MILLI)
Definition timetaker.h:34
void start()
Definition timetaker.cpp:11
u64 stop(bool quiet=false)
Definition timetaker.cpp:16
TimePrecision m_precision
Definition timetaker.h:61
u64 * m_result
Definition timetaker.h:58
std::string m_name
Definition timetaker.h:57
bool m_running
Definition timetaker.h:60
~TimeTaker()
Definition timetaker.h:45
u64 m_time1
Definition timetaker.h:59
u64 getTimerTime()
Definition timetaker.cpp:34
constexpr const char * TimePrecision_units[]
Definition timetaker.h:18
TimePrecision
Definition timetaker.h:11
@ PRECISION_SECONDS
Definition timetaker.h:12
@ PRECISION_NANO
Definition timetaker.h:15
@ PRECISION_MICRO
Definition timetaker.h:14
@ PRECISION_MILLI
Definition timetaker.h:13