mirai/libs/cpp-utils/debug.h
2024-04-30 16:57:34 +02:00

44 lines
1 KiB
C++

/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#ifndef CPP_UTILS_DEBUG_H
#define CPP_UTILS_DEBUG_H
#include <algorithm>
#include <chrono>
#include <iostream>
#include <ostream>
#include <string>
namespace cpputils::debug
{
class Timer
{
public:
Timer() : startTime(std::chrono::high_resolution_clock::now())
{
}
void start()
{
startTime = std::chrono::high_resolution_clock::now();
}
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)
<< " seconds" << std::endl;
}
private:
std::chrono::time_point<std::chrono::system_clock> startTime;
};
} // namespace cpputils::debug
#endif