mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 08:15:35 +00:00
28 lines
798 B
C++
28 lines
798 B
C++
#include "TScopedTimer.h"
|
|
#include "Common.h"
|
|
|
|
TScopedTimer::TScopedTimer()
|
|
: mStartTime(std::chrono::high_resolution_clock::now()) {
|
|
}
|
|
|
|
TScopedTimer::TScopedTimer(const std::string& mName)
|
|
: mStartTime(std::chrono::high_resolution_clock::now())
|
|
, Name(mName) {
|
|
}
|
|
|
|
TScopedTimer::TScopedTimer(std::function<void(size_t)> OnDestroy)
|
|
: OnDestroy(OnDestroy)
|
|
, mStartTime(std::chrono::high_resolution_clock::now()) {
|
|
}
|
|
|
|
TScopedTimer::~TScopedTimer() {
|
|
auto EndTime = std::chrono::high_resolution_clock::now();
|
|
auto Delta = EndTime - mStartTime;
|
|
size_t TimeDelta = Delta / std::chrono::milliseconds(1);
|
|
if (OnDestroy) {
|
|
OnDestroy(TimeDelta);
|
|
} else {
|
|
beammp_info("Scoped timer: \"" + Name + "\" took " + std::to_string(TimeDelta) + "ms ");
|
|
}
|
|
}
|