diff --git a/packages/react-native/src/private/webapis/structuredClone/__tests__/structuredClone-benchmark-itest.js b/packages/react-native/src/private/webapis/structuredClone/__tests__/structuredClone-benchmark-itest.js new file mode 100644 index 00000000000..165e087af41 --- /dev/null +++ b/packages/react-native/src/private/webapis/structuredClone/__tests__/structuredClone-benchmark-itest.js @@ -0,0 +1,44 @@ +/** + * 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 '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; + +import * as Fantom from '@react-native/fantom'; +import structuredClone from 'react-native/src/private/webapis/structuredClone/structuredClone'; + +const basicArray = [1, 2, 3]; +const basicObject = {a: 1, b: 2, c: 3}; +const complexObject = { + a: 1, + b: 'foo', + c: false, + d: undefined, + e: { + f: { + g: [1, 'foo', 'bar'], + }, + }, +}; + +Fantom.unstable_benchmark + .suite('structuredClone') + .test('clone a string', () => { + structuredClone('hello world'); + }) + .test('clone a basic array', () => { + structuredClone(basicArray); + }) + .test('clone a basic object', () => { + structuredClone(basicObject); + }) + .test('clone a complex object', () => { + structuredClone(complexObject); + });