Add: INR currency (#8136)
[openttd-github.git] / src / pathfinder / pf_performance_timer.hpp
blob66ec9695f8fe790e57da7059eaf84f4bc8308ab6
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file pf_performance_timer.hpp Performance timer for pathfinders. */
10 #ifndef PF_PERFORMANCE_TIMER_HPP
11 #define PF_PERFORMANCE_TIMER_HPP
13 #include "../debug.h"
15 struct CPerformanceTimer
17 int64 m_start;
18 int64 m_acc;
20 CPerformanceTimer() : m_start(0), m_acc(0) {}
22 inline void Start()
24 m_start = QueryTime();
27 inline void Stop()
29 m_acc += QueryTime() - m_start;
32 inline int Get(int64 coef)
34 return (int)(m_acc * coef / QueryFrequency());
37 inline int64 QueryTime()
39 return ottd_rdtsc();
42 inline int64 QueryFrequency()
44 return ((int64)2200 * 1000000);
48 struct CPerfStartReal
50 CPerformanceTimer *m_pperf;
52 inline CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf)
54 if (m_pperf != nullptr) m_pperf->Start();
57 inline ~CPerfStartReal()
59 Stop();
62 inline void Stop()
64 if (m_pperf != nullptr) {
65 m_pperf->Stop();
66 m_pperf = nullptr;
71 struct CPerfStartFake
73 inline CPerfStartFake(CPerformanceTimer& perf) {}
74 inline ~CPerfStartFake() {}
75 inline void Stop() {}
78 typedef CPerfStartFake CPerfStart;
80 #endif /* PF_PERFORMANCE_TIMER_HPP */