[render-test] Implement fps benchmarking tests (#15803)
This commit is contained in:
24
platform/default/src/mbgl/util/monotonic_timer.cpp
Normal file
24
platform/default/src/mbgl/util/monotonic_timer.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <assert.h>
|
||||
#include <chrono>
|
||||
#include <mbgl/util/monotonic_timer.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
// Prefer high resolution timer if it is monotonic
|
||||
template <typename T, std::enable_if_t<std::chrono::high_resolution_clock::is_steady, T>* = nullptr>
|
||||
static T sample() {
|
||||
return std::chrono::duration_cast<T>(std::chrono::high_resolution_clock::now().time_since_epoch());
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<!std::chrono::high_resolution_clock::is_steady, T>* = nullptr>
|
||||
static T sample() {
|
||||
return std::chrono::duration_cast<T>(std::chrono::steady_clock::now().time_since_epoch());
|
||||
}
|
||||
|
||||
std::chrono::duration<double> MonotonicTimer::now() {
|
||||
return sample<std::chrono::duration<double>>();
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user