/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-native/src/private/__tests__/utilities/measureRenderTime.js
46 строк
938 B
Rubén Norte
Add benchmark to compare rendering times for View and ViewNativeComponent (#53248)
13 авг 2025, 20:14
13 авг 2025, 20:14
d009a02
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format * @oncall react_native */ import * as Fantom from '@react-native/fantom'; import nullthrows from 'nullthrows'; const now = Fantom.unstable_benchmark.now; export default function measureRenderTime( root: Fantom.Root, elements: React.MixedElement, ): number { let startTime: ?number; let endTime: ?number; function RecordStart() { startTime ??= now(); return null; } function RecordEnd() { endTime = now(); return null; } Fantom.runTask(() => { // React renders nodes using a depth-first algorithm. root.render( <> <RecordStart /> {elements} <RecordEnd /> </>, ); }); return nullthrows(endTime) - nullthrows(startTime); }