Skip to content

Commit a69194e

Browse files
rubennortefacebook-github-bot
authored andcommitted
[skip ci] Add basic benchmarks for the Performance API (facebook#49638)
Summary: Changelog: [internal] This adds a basic benchmark for different use cases of the `performance` API. Baseline: | (index) | Task name | Latency average (ns) | Latency median (ns) | Throughput average (ops/s) | Throughput median (ops/s) | Samples | | ------- | --------------------------------------------------------- | -------------------- | ------------------- | -------------------------- | ------------------------- | ------- | | 0 | 'mark (default)' | '5692.08 ± 0.33%' | '5590.00' | '177735 ± 0.02%' | '178891' | 175683 | | 1 | 'mark (with custom startTime)' | '5775.21 ± 0.27%' | '5690.00' | '174880 ± 0.02%' | '175747' | 173154 | | 2 | 'measure (with start and end timestamps)' | '6842.61 ± 0.35%' | '6730.00' | '147672 ± 0.02%' | '148588' | 146144 | | 3 | 'measure (with mark names)' | '6828.01 ± 0.75%' | '6700.00' | '148371 ± 0.02%' | '149254' | 146456 | | 4 | 'clearMarks' | '817.04 ± 0.03%' | '800.00' | '1233054 ± 0.01%' | '1250000' | 1223933 | | 5 | 'clearMeasures' | '835.59 ± 0.03%' | '820.00' | '1203121 ± 0.01%' | '1219512' | 1196758 | | 6 | 'mark + clearMarks' | '6137.42 ± 1.32%' | '5920.00' | '167661 ± 0.02%' | '168919' | 162935 | | 7 | 'measure + clearMeasures (with start and end timestamps)' | '7353.85 ± 0.60%' | '7200.00' | '138196 ± 0.02%' | '138889' | 135984 | | 8 | 'measure + clearMeasures (with mark names)' | '7342.93 ± 0.66%' | '7170.00' | '138726 ± 0.02%' | '139470' | 136186 | Reviewed By: bgirard Differential Revision: D66926182
1 parent c66728d commit a69194e

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
* @oncall react_native
10+
* @fantom_mode opt
11+
*/
12+
13+
import '../../../../../Libraries/Core/InitializeCore.js';
14+
15+
import Fantom from '@react-native/fantom';
16+
17+
const clearMarksAndMeasures = () => {
18+
performance.clearMarks();
19+
performance.clearMeasures();
20+
};
21+
22+
Fantom.unstable_benchmark
23+
.suite('Performance API')
24+
.test(
25+
'mark (default)',
26+
() => {
27+
performance.mark('mark');
28+
},
29+
{
30+
afterEach: clearMarksAndMeasures,
31+
},
32+
)
33+
.test(
34+
'mark (with custom startTime)',
35+
() => {
36+
performance.mark('mark', {
37+
startTime: 100,
38+
});
39+
},
40+
{
41+
afterEach: clearMarksAndMeasures,
42+
},
43+
)
44+
.test(
45+
'measure (with start and end timestamps)',
46+
() => {
47+
performance.measure('measure', {
48+
start: 100,
49+
end: 300,
50+
});
51+
},
52+
{
53+
afterEach: clearMarksAndMeasures,
54+
},
55+
)
56+
.test(
57+
'measure (with mark names)',
58+
() => {
59+
performance.measure('measure', 'measure-start', 'measure-end');
60+
},
61+
{
62+
beforeEach: () => {
63+
performance.mark('measure-start', {
64+
startTime: 100,
65+
});
66+
performance.mark('measure-end', {
67+
startTime: 300,
68+
});
69+
},
70+
afterEach: clearMarksAndMeasures,
71+
},
72+
)
73+
.test(
74+
'clearMarks',
75+
() => {
76+
performance.clearMarks('mark');
77+
},
78+
{
79+
beforeEach: () => performance.mark('mark'),
80+
},
81+
)
82+
.test(
83+
'clearMeasures',
84+
() => {
85+
performance.clearMeasures('measure');
86+
},
87+
{
88+
beforeEach: () =>
89+
performance.measure('measure', {
90+
start: 100,
91+
end: 300,
92+
}),
93+
},
94+
)
95+
.test('mark + clearMarks', () => {
96+
performance.mark('mark');
97+
performance.clearMarks('mark');
98+
})
99+
.test('measure + clearMeasures (with start and end timestamps)', () => {
100+
performance.measure('measure', {
101+
start: 100,
102+
end: 300,
103+
});
104+
performance.clearMeasures('measure');
105+
})
106+
.test(
107+
'measure + clearMeasures (with mark names)',
108+
() => {
109+
performance.measure('measure', 'measure-start', 'measure-end');
110+
performance.clearMeasures('measure');
111+
},
112+
{
113+
beforeEach: () => {
114+
performance.mark('measure-start', {
115+
startTime: 100,
116+
});
117+
performance.mark('measure-end', {
118+
startTime: 300,
119+
});
120+
},
121+
afterEach: clearMarksAndMeasures,
122+
},
123+
);

0 commit comments

Comments
 (0)