-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ssr): add styled/slot benchmarks (#4783)
- Loading branch information
1 parent
b137d5d
commit e9db491
Showing
8 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...s/@lwc/perf-benchmarks/src/__benchmarks__/ssr/slots/slot-create-container-5k.benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { renderComponent } from '@lwc/ssr-runtime'; | ||
import SlotUsage from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/slotUsageComponent/slotUsageComponent.js'; | ||
import Store from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/store/store.js'; | ||
|
||
const SSR_MODE = 'asyncYield'; | ||
const NUMBER_OF_ROWS = 5000; | ||
|
||
benchmark(`ssr/slot/shadow/create/5k`, () => { | ||
let store; | ||
let rowsOfComponentWithSlot; | ||
let rowsOfSlottedContent; | ||
|
||
before(() => { | ||
store = new Store(); | ||
rowsOfComponentWithSlot = store.buildData(NUMBER_OF_ROWS); | ||
rowsOfSlottedContent = store.buildData(NUMBER_OF_ROWS); | ||
}); | ||
|
||
run(() => { | ||
const props = { | ||
rows: store.data, | ||
componentContent: 'Parent component slotting content to child cmp', | ||
rowsOfSlottedContent: rowsOfSlottedContent, | ||
titleOfComponentWithSlot: 'Component that receives a slot', | ||
rowsOfComponentWithSlot: rowsOfComponentWithSlot, | ||
}; | ||
return renderComponent('benchmark-slot-usage-component', SlotUsage, props, SSR_MODE); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
...chmarks/src/__benchmarks__/ssr/styled/light-styled-component-create-10k-same.benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import StyledComponent from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/light/styledComponent.js'; | ||
|
||
import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark'; | ||
|
||
const NUM_COMPONENTS = 10000; | ||
|
||
// Create 10k components with the same CSS in each component | ||
// These are light DOM components running in native mode | ||
styledComponentSsrBenchmark( | ||
`ssr/styled-component/light/create-same/10k`, | ||
NUM_COMPONENTS, | ||
StyledComponent, | ||
{ after, before, benchmark, run } | ||
); |
21 changes: 21 additions & 0 deletions
21
...rks/src/__benchmarks__/ssr/styled/light-styled-component-create-1k-different.benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import components from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/light/styledComponents.js'; | ||
|
||
import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark'; | ||
|
||
const NUM_COMPONENTS = 1000; | ||
|
||
// Create 1k components with different CSS in each component | ||
// These are light DOM components running in native mode | ||
styledComponentSsrBenchmark( | ||
`ssr/styled-component/light/create-different/1k`, | ||
NUM_COMPONENTS, | ||
components, | ||
{ after, before, benchmark, run } | ||
); |
20 changes: 20 additions & 0 deletions
20
...rf-benchmarks/src/__benchmarks__/ssr/styled/styled-component-create-10k-same.benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import StyledComponent from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/shadow/styledComponent.js'; | ||
|
||
import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark'; | ||
|
||
const NUM_COMPONENTS = 10000; | ||
|
||
// Create 10k components with the same CSS in each component | ||
styledComponentSsrBenchmark( | ||
`ssr/styled-component/shadow/create-same/10k`, | ||
NUM_COMPONENTS, | ||
StyledComponent, | ||
{ after, before, benchmark, run } | ||
); |
20 changes: 20 additions & 0 deletions
20
...enchmarks/src/__benchmarks__/ssr/styled/styled-component-create-1k-different.benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import components from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/shadow/styledComponents.js'; | ||
|
||
import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark'; | ||
|
||
const NUM_COMPONENTS = 1000; | ||
|
||
// Create 1k components with different CSS in each component | ||
styledComponentSsrBenchmark( | ||
`ssr/styled-component/shadow/create-different/1k`, | ||
NUM_COMPONENTS, | ||
components, | ||
{ after, before, benchmark, run } | ||
); |
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
packages/@lwc/perf-benchmarks/src/utils/styledComponentSsrBenchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { renderComponent } from '@lwc/ssr-runtime'; | ||
|
||
const SSR_MODE = 'asyncYield'; | ||
|
||
// Generic benchmark for styled components, SSR-flavored! | ||
export function styledComponentSsrBenchmark( | ||
name, | ||
numComponents, | ||
componentOrComponents, | ||
{ benchmark, run } | ||
) { | ||
benchmark(name, () => { | ||
const isArray = Array.isArray(componentOrComponents); | ||
|
||
run(async () => { | ||
for (let i = 0; i < numComponents; i++) { | ||
await renderComponent( | ||
isArray ? `styled-component${i}` : 'styled-component', | ||
isArray ? componentOrComponents[i] : componentOrComponents, | ||
{}, | ||
SSR_MODE | ||
); | ||
} | ||
}); | ||
}); | ||
} |