Unify native performanceNow implementation across platforms

Summary:
[Changelog][Internal]

Both iOS and Android platforms are at this point using the same native implementation of `performanceNow`, based on `std::chrono` (it used to be different some time ago).

This diff unifies the implementations, so it comes from one place in C++ code for all platforms.

The context is that I am developing event timing instrumentation and need a consistent way to get current timestamp from either JS or native (C++) side. The latter is now possible via calling `JSExecutor::performanceNow()`, which is guaranteed to be the same as called from JS.

Reviewed By: christophpurrer

Differential Revision: D42267898

fbshipit-source-id: dcb592f37d6567340ea59faddbf3b6d2b8507d50
This commit is contained in:
Ruslan Shestopalyuk
2022-12-28 11:03:14 -08:00
committed by Facebook GitHub Bot
parent 673d7e81a2
commit ad953f6f4b
9 changed files with 25 additions and 72 deletions
+12
View File
@@ -11,6 +11,8 @@
#include <folly/Conv.h>
#include <chrono>
namespace facebook {
namespace react {
@@ -23,5 +25,15 @@ std::string JSExecutor::getSyntheticBundlePath(
return folly::to<std::string>("seg-", bundleId, ".js");
}
double JSExecutor::performanceNow() {
auto time = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
time.time_since_epoch())
.count();
constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0;
return duration / NANOSECONDS_IN_MILLISECOND;
}
} // namespace react
} // namespace facebook