mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook GitHub Bot
parent
673d7e81a2
commit
ad953f6f4b
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user