Improve startup time

This commit is contained in:
Vyn 2024-04-30 18:18:54 +02:00
parent d90bfbc483
commit 597ea0ac2d
10 changed files with 82 additions and 23 deletions

View file

@ -26,18 +26,40 @@ class Timer
void start()
{
startTime = std::chrono::high_resolution_clock::now();
isRunning = true;
}
void stop()
{
const auto now = std::chrono::high_resolution_clock::now();
duration += std::chrono::duration_cast<std::chrono::microseconds>(now - startTime).count();
isRunning = false;
}
void reset()
{
duration = 0;
isRunning = false;
}
void printTimeElapsed(const std::string &message) const
{
const auto now = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(now - startTime);
std::cout << "[Debug - Timer] " << message << ": " << ((double)duration.count() / 1000000)
long durationToShow = duration;
if (isRunning) {
const auto now = std::chrono::high_resolution_clock::now();
durationToShow +=
std::chrono::duration_cast<std::chrono::microseconds>(now - startTime).count();
}
std::cout << "[Debug - Timer] " << message << ": " << ((double)durationToShow / 1000000)
<< " seconds" << std::endl;
}
private:
std::chrono::time_point<std::chrono::system_clock> startTime;
// Timer are always running when created. You can use .reset() after creation.
bool isRunning = true;
long duration;
};
} // namespace cpputils::debug