diff --git a/src/utils/timer.hpp b/src/utils/timer.hpp index 5d878d8..9541f66 100644 --- a/src/utils/timer.hpp +++ b/src/utils/timer.hpp @@ -1,33 +1,57 @@ #ifndef SPECMICP_UTILS_TIMER_HPP #define SPECMICP_UTILS_TIMER_HPP #include <chrono> +#include <ctime> namespace specmicp { //! \brief A simple timer class Timer { public: //! \brief Start the timer void start() { m_start = std::chrono::system_clock::now(); } //! \brief Stop the timer void stop() { m_end = std::chrono::system_clock::now(); } + + //! \brief Return the time of the starting point + std::time_t get_start() const { + return std::chrono::system_clock::to_time_t(m_start); + } + + //! \brief Return the time of the ending point + std::time_t get_stop() const { + return std::chrono::system_clock::to_time_t(m_end); + } + + //! \brief Return a textual representation of the starting point + char* get_ctime_start() const { + std::time_t start_time = get_start(); + return std::ctime(&start_time); + } + + //! \brief Return a textual representation of the ending point + char* get_ctime_stop() const { + std::time_t stop_time = get_stop(); + return std::ctime(&stop_time); + } + //! \brief Return the elapsed time (in seconds) - double elapsed_time() { + double elapsed_time() const { std::chrono::duration<double> elapsed_seconds = m_end-m_start; return elapsed_seconds.count(); } private: std::chrono::time_point<std::chrono::system_clock> m_start; std::chrono::time_point<std::chrono::system_clock> m_end; }; } // end namespace specmicp #endif // SPECMICP_UTILS_TIMER_HPP