Skip to content

Commit 6d52cf5

Browse files
rshestfacebook-github-bot
authored andcommitted
Create Fantom benchmark test for Text component (#52836)
Summary: Pull Request resolved: #52836 # Changelog [Internal] - This adds a basic benchmarking test for `Text` component creation, similarly to the one we already have for the e.g. `View`. Reviewed By: rubennorte Differential Revision: D78975332 fbshipit-source-id: e1b54e59a54e8c7f8f19738f2ffeaa02ca5c09ee
1 parent 012b78c commit 6d52cf5

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
12+
13+
import * as Fantom from '@react-native/fantom';
14+
import * as React from 'react';
15+
import {Text} from 'react-native';
16+
17+
let root;
18+
let testElements: React.MixedElement;
19+
20+
Fantom.unstable_benchmark.suite('Text').test.each(
21+
[100, 1000],
22+
n => `render ${n.toString()} text component instances`,
23+
() => {
24+
Fantom.runTask(() => root.render(testElements));
25+
},
26+
n => ({
27+
beforeAll: () => {
28+
testElements = (
29+
<>
30+
{[...Array(n).keys()].map(i => (
31+
<Text
32+
id={String(i)}
33+
nativeID={String(i)}
34+
style={{
35+
width: i + 1,
36+
height: i + 1,
37+
}}>{`Text instance ${i}`}</Text>
38+
))}
39+
</>
40+
);
41+
},
42+
beforeEach: () => {
43+
root = Fantom.createRoot();
44+
},
45+
afterEach: () => {
46+
root.destroy();
47+
},
48+
}),
49+
);

0 commit comments

Comments
 (0)