Skip to content

Commit 4be0850

Browse files
committed
Update benchmarks
1 parent 71e2c61 commit 4be0850

File tree

18 files changed

+2524
-1233
lines changed

18 files changed

+2524
-1233
lines changed

.prettierrc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{
2-
"trailingComma": "es5",
3-
"tabWidth": 2,
2+
"printWidth": 120,
3+
"semi": false,
44
"singleQuote": true,
5-
"printWidth": 120
6-
}
5+
"tabWidth": 2,
6+
"trailingComma": "es5",
7+
"useTabs": true,
8+
"overrides": [
9+
{
10+
"files": ["*.json", ".prettierrc"],
11+
"options": {
12+
"useTabs": false
13+
}
14+
}
15+
]
16+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"browser-preview.startUrl": "https://localhost:3000/"
3+
}

jsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["dom", "ESNext"],
4+
"module": "commonjs",
5+
"target": "es6"
6+
},
7+
"exclude": ["node_modules"]
8+
}

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"name": "stitches-benchmark",
33
"version": "1.0.0",
4-
"description": "",
5-
"keywords": [],
6-
"main": "",
4+
"license": "MIT",
75
"dependencies": {},
86
"devDependencies": {},
97
"scripts": {}
Binary file not shown.

styled-components/package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44
"description": "",
55
"keywords": [],
66
"main": "src/index.js",
7+
"files": [
8+
"public",
9+
"src"
10+
],
11+
"license": "MIT",
712
"dependencies": {
13+
"@emotion/core": "^10.0.35",
14+
"@emotion/styled": "^10.0.27",
15+
"@loadable/component": "5.14.0",
816
"@stitches/react": "0.0.2",
9-
"react": "16.12.0",
10-
"react-dom": "16.12.0",
11-
"react-scripts": "3.0.1",
12-
"styled-components": "5.1.1"
17+
"@stitches/react-canary": "file:bundledDependencies/react-0.0.3-canary.4.tar.gz",
18+
"react": "17.0.0",
19+
"react-dom": "17.0.0",
20+
"react-router-dom": "5.2.0",
21+
"react-scripts": "3.4.4",
22+
"styled-components": "5.2.0"
1323
},
1424
"devDependencies": {
15-
"typescript": "3.8.3"
25+
"typescript": "4.0.3"
1626
},
1727
"scripts": {
1828
"start": "react-scripts start",
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
4-
<head>
5-
<meta charset="utf-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7-
8-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
9-
<!--
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
6+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
7+
<!--
108
Notice the use of %PUBLIC_URL% in the tags above.
119
It will be replaced with the URL of the `public` folder during the build.
1210
Only files inside the `public` folder can be referenced from the HTML.
@@ -15,15 +13,13 @@
1513
work correctly both with client-side routing and a non-root public URL.
1614
Learn how to configure a non-root public URL by running `npm run build`.
1715
-->
18-
<title>Stitches Benchmark</title>
19-
</head>
20-
21-
<body>
22-
<noscript>
23-
You need to enable JavaScript to run this app.
24-
</noscript>
25-
<div id="root"><p>Check console logs 👀</p></div>
26-
<!--
16+
<title>Stitches Benchmark</title>
17+
</head>
18+
<body>
19+
<noscript> You need to enable JavaScript to run this app. </noscript>
20+
<div id="root"></div>
21+
<div id="test"></div>
22+
<!--
2723
This HTML file is a template.
2824
If you open it directly in the browser, you will see an empty page.
2925
@@ -33,6 +29,5 @@
3329
To begin the development, run `npm start` or `yarn start`.
3430
To create a production bundle, use `npm run build` or `yarn build`.
3531
-->
36-
</body>
37-
32+
</body>
3833
</html>

styled-components/src/index.js

Lines changed: 23 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,23 @@
1-
import React from 'react';
2-
import scStyled from 'styled-components';
3-
import { renderToString } from 'react-dom/server';
4-
import { createStyled } from '@stitches/react';
5-
6-
const { styled: stitchesStyled } = createStyled({});
7-
8-
const LOOP = 2000;
9-
10-
/**
11-
* SETUP: STYLED COMPONENTS
12-
*/
13-
const ScBaseComponent = scStyled.h1({
14-
color: 'blue',
15-
padding: '1rem',
16-
});
17-
18-
const ScOverrideBaseComponent = scStyled(ScBaseComponent)({
19-
color: 'red',
20-
paddingTop: '5rem',
21-
});
22-
23-
const ScDynamicComponent = scStyled.div((props) => ({
24-
opacity: props.disabled ? 0.5 : 1,
25-
}));
26-
27-
const ScTest1 = () => {
28-
return <ScOverrideBaseComponent>Hello Test</ScOverrideBaseComponent>;
29-
};
30-
31-
const ScTest2 = () => {
32-
return (
33-
<div>
34-
<ScDynamicComponent disabled>Hello Test</ScDynamicComponent>
35-
<ScDynamicComponent disabled={false}>Hello Test</ScDynamicComponent>
36-
</div>
37-
);
38-
};
39-
40-
/**
41-
* SETUP: STITCHES
42-
*/
43-
const StitchesBaseComponent = stitchesStyled.h1({
44-
color: 'blue',
45-
padding: '1rem',
46-
});
47-
48-
const StitchesOverrideBaseComponent = stitchesStyled(StitchesBaseComponent, {
49-
color: 'red',
50-
paddingTop: '5rem',
51-
});
52-
53-
const StitchesDynamicComponent = scStyled.div({
54-
variants: {
55-
variant: {
56-
muted: {
57-
opacity: 0.5,
58-
},
59-
},
60-
},
61-
});
62-
63-
const StitchesTest1 = () => {
64-
return <StitchesOverrideBaseComponent>Hello Test</StitchesOverrideBaseComponent>;
65-
};
66-
67-
const StitchesTest2 = () => {
68-
return (
69-
<div>
70-
<StitchesDynamicComponent variant="muted">Hello Test</StitchesDynamicComponent>
71-
<StitchesDynamicComponent>Hello Test</StitchesDynamicComponent>
72-
</div>
73-
);
74-
};
75-
76-
let start;
77-
78-
/**
79-
* RUN: STYLED-COMPONENTS
80-
*/
81-
start = performance.now();
82-
for (let x = 0; x < LOOP; x++) {
83-
scStyled.div({
84-
padding: x + 'px',
85-
});
86-
}
87-
const ScDefineUnique = performance.now() - start;
88-
89-
start = performance.now();
90-
for (let x = 0; x < LOOP; x++) {
91-
scStyled.div({
92-
color: 'red',
93-
});
94-
}
95-
const ScDefineSame = performance.now() - start;
96-
97-
start = performance.now();
98-
for (let x = 0; x < LOOP; x++) {
99-
renderToString(<ScTest1 />);
100-
}
101-
const ScConsumeStatic = performance.now() - start;
102-
103-
start = performance.now();
104-
for (let x = 0; x < LOOP; x++) {
105-
renderToString(<ScTest2 />);
106-
}
107-
const ScConsumeDynamic = performance.now() - start;
108-
109-
/**
110-
* RUN: STITCHES
111-
*/
112-
start = performance.now();
113-
for (let x = 0; x < LOOP; x++) {
114-
stitchesStyled.div({
115-
padding: x + 'px',
116-
});
117-
}
118-
const StitchesDefineUnique = performance.now() - start;
119-
120-
start = performance.now();
121-
for (let x = 0; x < LOOP; x++) {
122-
stitchesStyled.div({
123-
color: 'red',
124-
});
125-
}
126-
const StitchesDefineSame = performance.now() - start;
127-
128-
start = performance.now();
129-
for (let x = 0; x < LOOP; x++) {
130-
renderToString(<StitchesTest1 />);
131-
}
132-
const StitchesConsumeStatic = performance.now() - start;
133-
134-
start = performance.now();
135-
for (let x = 0; x < LOOP; x++) {
136-
renderToString(<StitchesTest2 />);
137-
}
138-
const StitchesConsumeDynamic = performance.now() - start;
139-
140-
console.table({
141-
'STYLED-COMPONENTS': {
142-
'define unique': ScDefineUnique,
143-
'define same': ScDefineSame,
144-
'consume static': ScConsumeStatic,
145-
'consume dynamic': ScConsumeDynamic,
146-
},
147-
STITCHES: {
148-
'define unique': StitchesDefineUnique,
149-
'define same': StitchesDefineSame,
150-
'consume static': StitchesConsumeStatic,
151-
'consume dynamic': StitchesConsumeDynamic,
152-
},
153-
'STITCHES PERF': {
154-
'define unique': Math.floor((ScDefineUnique / StitchesDefineUnique) * 100) / 100 + 'x',
155-
'define same': Math.floor((ScDefineSame / StitchesDefineSame) * 100) / 100 + 'x',
156-
'consume static': Math.floor((ScConsumeStatic / StitchesConsumeStatic) * 100) / 100 + 'x',
157-
'consume dynamic': Math.floor((ScConsumeDynamic / StitchesConsumeDynamic) * 100) / 100 + 'x',
158-
},
159-
});
1+
import * as ReactDOM from 'react-dom'
2+
import * as React from 'react'
3+
import * as Router from 'react-router-dom'
4+
import loadable from '@loadable/component'
5+
import './style.css'
6+
7+
const AsyncPage = loadable((props) => import(`./pages${props.location.pathname.replace(/\/$/, '') || '/index'}.js`), {
8+
cacheKey: (props) => props.location,
9+
})
10+
11+
function App() {
12+
const location = Router.useLocation()
13+
return <AsyncPage location={location} />
14+
}
15+
16+
ReactDOM.render(
17+
<React.StrictMode>
18+
<Router.BrowserRouter>
19+
<App />
20+
</Router.BrowserRouter>
21+
</React.StrictMode>,
22+
window.root
23+
)

0 commit comments

Comments
 (0)