#pragma once #include #include #include #include class Timer { public: Timer() { Reset(); } void Reset() { m_Start = std::chrono::high_resolution_clock::now(); } float Elapsed() { return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_Start).count() * 0.001f * 0.001f * 0.001f; } float ElapsedMillis() { return Elapsed() * 1000.0f; } long long Stamp_millis() { // Get the current time point with nanosecond precision auto now = std::chrono::system_clock::now(); // Calculate the number of nanoseconds since the epoch auto since_epoch = now.time_since_epoch(); long long milliseconds = std::chrono::duration_cast(since_epoch).count(); return milliseconds; } std::string GetFileStamp() { time_t now = time(nullptr); struct tm* ltm = localtime(&now); std::string stamp = std::to_string(1900 + ltm->tm_year) + "_" + std::to_string(1 + ltm->tm_mon) + "_" + std::to_string(ltm->tm_mday) + "_" + std::to_string(ltm->tm_hour) + "_" + std::to_string(ltm->tm_min); //printf(stamp.c_str()); return stamp; } std::string GetStringStamp() { time_t now = time(nullptr); struct tm* ltm = localtime(&now); std::string stamp = std::to_string(1900 + ltm->tm_year) + "_" + std::to_string(1 + ltm->tm_mon) + "_" + std::to_string(ltm->tm_mday) + "_" + std::to_string(ltm->tm_hour) + "_" + std::to_string(ltm->tm_min) + "_" + std::to_string(ltm->tm_sec); //printf(stamp.c_str()); return stamp; } std::string GetDirStamp() { time_t now = time(nullptr); struct tm* ltm = localtime(&now); std::string stamp = std::to_string(1900 + ltm->tm_year) + "_" + std::to_string(1 + ltm->tm_mon) + "_" + std::to_string(ltm->tm_mday) + "_" + std::to_string(ltm->tm_hour); //printf(stamp.c_str()); return stamp; } private: std::chrono::time_point m_Start; }; class ScopedTimer { public: ScopedTimer(const std::string& name) : m_Name(name) {} ~ScopedTimer() { float time = m_Timer.ElapsedMillis(); std::cout << "[TIMER] " << m_Name << " - " << time << "ms\n"; } private: std::string m_Name; Timer m_Timer; }; class NanoUnixTimer { public: std::string Stamp_string() { // Get the current time point with nanosecond precision auto now = std::chrono::system_clock::now(); // Calculate the number of nanoseconds since the epoch auto since_epoch = now.time_since_epoch(); auto milliseconds = std::chrono::duration_cast(since_epoch).count(); // Convert the nanoseconds to a string return std::to_string(milliseconds); } long long Stamp_longlong() { // Get the current time point with nanosecond precision auto now = std::chrono::system_clock::now(); // Calculate the number of nanoseconds since the epoch auto since_epoch = now.time_since_epoch(); long long milliseconds = std::chrono::duration_cast(since_epoch).count(); return milliseconds; } };