.. _program_listing_file__tmp_ws_src_proxsuite_include_proxsuite_proxqp_timings.hpp: Program Listing for File timings.hpp ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/proxsuite/include/proxsuite/proxqp/timings.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // // Copyright (c) 2022 INRIA // #ifndef PROXSUITE_PROXQP_TIMINGS_HPP #define PROXSUITE_PROXQP_TIMINGS_HPP #include namespace proxsuite { namespace proxqp { struct CPUTimes { double wall; double user; double system; CPUTimes() : wall(0) , user(0) , system(0) { } void clear() { wall = user = system = 0; } }; template struct Timer { Timer() : m_is_stopped(true) { start(); } CPUTimes elapsed() const { if (m_is_stopped) return m_times; CPUTimes current(m_times); std::chrono::time_point current_clock = std::chrono::steady_clock::now(); current.user += static_cast(std::chrono::duration_cast( current_clock - m_start) .count()) * 1e-3; return current; } void start() { if (m_is_stopped) { m_is_stopped = false; m_times.clear(); m_start = std::chrono::steady_clock::now(); } } void stop() { if (m_is_stopped) return; m_is_stopped = true; m_end = std::chrono::steady_clock::now(); m_times.user += static_cast( std::chrono::duration_cast(m_end - m_start) .count()) * 1e-3; } void resume() { if (m_is_stopped) m_start = std::chrono::steady_clock::now(); } bool is_stopped() const { return m_is_stopped; } protected: CPUTimes m_times; bool m_is_stopped; std::chrono::time_point m_start, m_end; }; } // namespace proxqp } // namespace proxsuite #endif // ifndef PROXSUITE_PROXQP_TIMINGS_HPP