/
vasandi
/
AirSim
Обзор
Документация
Войти
/
vasandi
/
AirSim
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
AirLib/include/common/common_utils/Timer.hpp
61 строка
1 KB
Андрей Васильченко
сборка под ubuntu 26.04
08 июл 2026, 10:15
08 июл 2026, 10:15
d53c5a2
Код
Авторство
О чём код?
#ifndef CommonUtils_Timer_hpp #define CommonUtils_Timer_hpp #include <chrono> #include "Utils.hpp" namespace common_utils { class Timer { public: Timer() { started_ = false; } void start() { started_ = true; start_ = now(); } void stop() { started_ = false; end_ = now(); } double seconds() { auto diff = static_cast<double>(end() - start_); return diff / 1000000.0; } double milliseconds() { return static_cast<double>(end() - start_) / 1000.0; } double microseconds() { return static_cast<double>(end() - start_); } bool started() { return started_; } private: int64_t now() { return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); } int64_t end() { if (started_) { // not stopped yet, so return "elapsed time so far". end_ = now(); } return end_; } int64_t start_; int64_t end_; bool started_; }; } #endif