mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 10:13:42 +00:00
Improve startup time
This commit is contained in:
parent
d90bfbc483
commit
597ea0ac2d
10 changed files with 82 additions and 23 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue