diff --git a/packages/react-native/Libraries/Animated/__tests__/Animated-benchmark-itest.js b/packages/react-native/Libraries/Animated/__tests__/Animated-benchmark-itest.js new file mode 100644 index 00000000000..8e5e2c41633 --- /dev/null +++ b/packages/react-native/Libraries/Animated/__tests__/Animated-benchmark-itest.js @@ -0,0 +1,133 @@ +/** + * 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 + */ + +import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; + +import * as Fantom from '@react-native/fantom'; +import * as React from 'react'; +import {Animated, View, useAnimatedValue} from 'react-native'; + +function MyApp() { + return ( + + ); +} + +function MyAnimatedApp() { + return ( + + ); +} + +function MyAnimatedAppWithAnimation() { + const opacity = useAnimatedValue(1); + + return ( + + ); +} + +function MyAnimatedAppWithNativeAnimation() { + const opacity = useAnimatedValue(1, {useNativeDriver: true}); + + return ( + + ); +} + +const ARGS = [1, 10, 100]; + +let root = Fantom.createRoot(); +let element: React.MixedElement; + +function renderElement() { + Fantom.runTask(() => root.render(element)); +} + +function getOptions( + numberOfComponents: number, + Component: React.ComponentType<{}>, +): Fantom.BenchmarkTestOptions { + return { + beforeAll: () => { + element = ( + <> + {Array.from({length: numberOfComponents}, (_, i) => ( + + ))} + + ); + }, + beforeEach: () => { + Fantom.runTask(() => root.render(<>)); + }, + }; +} + +Fantom.unstable_benchmark + .suite('Animated') + .test.each( + ARGS, + n => `render ${n} views`, + renderElement, + n => getOptions(n, MyApp), + ) + .test.each( + ARGS, + n => `render ${n} animated views (without animations set up)`, + renderElement, + n => getOptions(n, MyAnimatedApp), + ) + .test.each( + ARGS, + n => + `render ${n} animated views (with a single animation set up - JS driven)`, + renderElement, + n => getOptions(n, MyAnimatedAppWithAnimation), + ) + .test.each( + ARGS, + n => + `render ${n} animated views (with a single animation set up - native driven)`, + renderElement, + n => getOptions(n, MyAnimatedAppWithNativeAnimation), + );