metaforce/Runtime/CStopwatch.hpp

26 lines
742 B
C++
Raw Normal View History

2018-10-06 20:42:33 -07:00
#pragma once
2017-11-18 23:10:54 -08:00
#include <chrono>
2018-12-07 21:30:43 -08:00
namespace urde {
class CStopwatch {
std::chrono::steady_clock::time_point m_start;
2017-11-18 23:10:54 -08:00
public:
2018-12-07 21:30:43 -08:00
CStopwatch() : m_start(std::chrono::steady_clock::now()) {}
2019-06-05 17:07:50 -07:00
double report(const char* name) const {
double t = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - m_start).count() / 1000000.0;
printf("%s %f\n", name, t);
return t;
2018-12-07 21:30:43 -08:00
}
2019-06-05 17:07:50 -07:00
double reportReset(const char* name) {
2018-12-07 21:30:43 -08:00
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
2019-06-05 17:07:50 -07:00
double t = std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count() / 1000000.0;
printf("%s %f\n", name, t);
2018-12-07 21:30:43 -08:00
m_start = now;
2019-06-05 17:07:50 -07:00
return t;
2018-12-07 21:30:43 -08:00
}
2017-11-18 23:10:54 -08:00
};
2018-12-07 21:30:43 -08:00
} // namespace urde