summaryrefslogtreecommitdiff
path: root/platform/default/src/mbgl/util/monotonic_timer.cpp
diff options
context:
space:
mode:
authorMikko Pulkki <55925868+mpulkki-mapbox@users.noreply.github.com>2019-10-22 12:13:55 +0300
committerGitHub <noreply@github.com>2019-10-22 12:13:55 +0300
commit0ca96fd8a402ae530da72e3955196007a2ec365f (patch)
treec1fc1b6194261bdcf3d3243d75368f7bf396e78a /platform/default/src/mbgl/util/monotonic_timer.cpp
parentbb0e5ffb2ceea28d386a9ac317ab9e1e81d83b07 (diff)
downloadqtlocation-mapboxgl-0ca96fd8a402ae530da72e3955196007a2ec365f.tar.gz
[render-test] Implement fps benchmarking tests (#15803)
Diffstat (limited to 'platform/default/src/mbgl/util/monotonic_timer.cpp')
-rw-r--r--platform/default/src/mbgl/util/monotonic_timer.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/platform/default/src/mbgl/util/monotonic_timer.cpp b/platform/default/src/mbgl/util/monotonic_timer.cpp
new file mode 100644
index 0000000000..43c2ce6717
--- /dev/null
+++ b/platform/default/src/mbgl/util/monotonic_timer.cpp
@@ -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 \ No newline at end of file