metaforce/Runtime/CStopwatch.hpp

32 lines
897 B
C++
Raw Permalink Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2017-11-19 07:10:54 +00:00
#include <chrono>
#include <fmt/format.h>
2017-11-19 07:10:54 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2018-12-08 05:30:43 +00:00
class CStopwatch {
std::chrono::steady_clock::time_point m_start;
2017-11-19 07:10:54 +00:00
public:
2018-12-08 05:30:43 +00:00
CStopwatch() : m_start(std::chrono::steady_clock::now()) {}
2019-06-06 00:07:50 +00:00
double report(const char* name) const {
2021-06-07 19:29:18 +00:00
double t =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - m_start).count() /
1000000.0;
//#ifndef NDEBUG
// fmt::print(FMT_STRING("{} {}\n"), name, t);
//#endif
2019-06-06 00:07:50 +00:00
return t;
2018-12-08 05:30:43 +00:00
}
2019-06-06 00:07:50 +00:00
double reportReset(const char* name) {
2018-12-08 05:30:43 +00:00
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
2019-06-06 00:07:50 +00:00
double t = std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count() / 1000000.0;
2021-06-07 19:29:18 +00:00
//#ifndef NDEBUG
// fmt::print(FMT_STRING("{} {}\n"), name, t);
//#endif
2018-12-08 05:30:43 +00:00
m_start = now;
2019-06-06 00:07:50 +00:00
return t;
2018-12-08 05:30:43 +00:00
}
2017-11-19 07:10:54 +00:00
};
2021-04-10 08:42:06 +00:00
} // namespace metaforce