1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Timer { private: using clock_t = std::chrono::high_resolution_clock; using second_t = std::chrono::duration<double, std::ratio<1>>;
std::chrono::time_point<clock_t> m_start_time;
public: Timer() : m_start_time(clock_t::now()) {}
~Timer() { auto end_time = clock_t::now(); auto elapsed_time = std::chrono::duration_cast<second_t>(end_time - m_start_time).count(); std::cout << std::fixed << std::setprecision(6) << "Elapsed time: " << elapsed_time << " seconds" << std::endl; } };
|