Skip to content

Commit d351837

Browse files
rubennortefacebook-github-bot
authored andcommitted
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 | Differential Revision: D66926182
1 parent 92e2168 commit d351837

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
performance.mark('measure-start', {
18+
startTime: 100,
19+
});
20+
21+
performance.mark('measure-end', {
22+
startTime: 300,
23+
});
24+
25+
Fantom.unstable_benchmark
26+
.suite('Performance API')
27+
.test(
28+
'mark (default)',
29+
() => {
30+
performance.mark('mark');
31+
},
32+
{
33+
afterEach: () => performance.clearMarks('mark'),
34+
},
35+
)
36+
.test(
37+
'mark (with custom startTime)',
38+
() => {
39+
performance.mark('mark', {
40+
startTime: 100,
41+
});
42+
},
43+
{
44+
afterEach: () => performance.clearMarks('mark'),
45+
},
46+
)
47+
.test(
48+
'measure (with start and end timestamps)',
49+
() => {
50+
performance.measure('measure', {
51+
start: 100,
52+
end: 300,
53+
});
54+
},
55+
{
56+
afterEach: () => performance.clearMeasures('measure'),
57+
},
58+
)
59+
.test(
60+
'measure (with mark names)',
61+
() => {
62+
performance.measure('measure', 'measure-start', 'measure-end');
63+
},
64+
{
65+
afterEach: () => performance.clearMeasures('measure'),
66+
},
67+
)
68+
.test(
69+
'clearMarks',
70+
() => {
71+
performance.clearMarks('mark');
72+
},
73+
{
74+
beforeEach: () => performance.mark('mark'),
75+
},
76+
)
77+
.test(
78+
'clearMeasures',
79+
() => {
80+
performance.clearMeasures('measure');
81+
},
82+
{
83+
beforeEach: () =>
84+
performance.measure('measure', {
85+
start: 100,
86+
end: 300,
87+
}),
88+
},
89+
)
90+
.test('mark + clearMarks', () => {
91+
performance.mark('mark');
92+
performance.clearMarks('mark');
93+
})
94+
.test('measure + clearMeasures (with start and end timestamps)', () => {
95+
performance.measure('measure', {
96+
start: 100,
97+
end: 300,
98+
});
99+
performance.clearMeasures('measure');
100+
})
101+
.test('measure + clearMeasures (with mark names)', () => {
102+
performance.measure('measure', 'measure-start', 'measure-end');
103+
performance.clearMeasures('measure');
104+
});

0 commit comments

Comments
 (0)