mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-06 07:46:06 +00:00
Add ScopedTimer, Remove some comments
This commit is contained in:
27
src/TScopedTimer.cpp
Normal file
27
src/TScopedTimer.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#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 ");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user