mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add benchmark for structuredClone (#51249)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51249 Changelog: [internal] This adds a basic benchmark for `structuredClone`, so we can optimize it in the following diff. Baseline: | (index) | Task name | Latency average (ns) | Latency median (ns) | Throughput average (ops/s) | Throughput median (ops/s) | Samples | | ------- | ------------------------ | -------------------- | ------------------- | -------------------------- | ------------------------- | ------- | | 0 | 'clone a string' | '955.81 ± 1.45%' | '902.00' | '1095925 ± 0.01%' | '1108647' | 1046239 | | 1 | 'clone a basic array' | '7684.79 ± 0.76%' | '7542.00' | '131980 ± 0.02%' | '132591' | 130128 | | 2 | 'clone a basic object' | '6286.35 ± 0.53%' | '6179.00' | '161179 ± 0.02%' | '161838' | 159075 | | 3 | 'clone a complex object' | '22446.96 ± 0.32%' | '22223.00' | '44819 ± 0.03%' | '44998' | 44550 | Reviewed By: hoxyq Differential Revision: D71407319 fbshipit-source-id: ee1c89d6ba3fd2484b2f4115cc58dc4b08e04fa7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
46b55d2146
commit
f7327bddb5
+44
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user