Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Update benchmark #14065

Merged
merged 2 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/material-ui-benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ Markdown x 954 ops/sec ±1.35% (187 runs sampled)
```sh
yarn styles

Box x 3,854 ops/sec ±1.73% (189 runs sampled)
JSS naked x 35,830 ops/sec ±1.30% (186 runs sampled)
WithStylesButton x 15,551 ops/sec ±1.86% (189 runs sampled)
HookButton x 21,649 ops/sec ±0.63% (190 runs sampled)
StyledComponentsButton x 7,728 ops/sec ±1.46% (189 runs sampled)
EmotionButton x 8,821 ops/sec ±7.96% (149 runs sampled)
Naked x 31,835 ops/sec ±7.60% (167 runs sampled)
hashing x 171,955 ops/sec ±5.22% (164 runs sampled)
Box x 3,850 ops/sec ±3.58% (178 runs sampled)
JSS naked x 35,493 ops/sec ±2.29% (183 runs sampled)
WithStylesButton x 16,844 ops/sec ±0.34% (191 runs sampled)
HookButton x 23,213 ops/sec ±0.88% (191 runs sampled)
StyledComponentsButton x 7,442 ops/sec ±2.09% (180 runs sampled)
EmotionButton x 11,345 ops/sec ±2.45% (185 runs sampled)
EmotionCssButton x 53,807 ops/sec ±0.40% (191 runs sampled)
EmotionServerCssButton x 43,701 ops/sec ±1.04% (190 runs sampled)
Naked x 58,694 ops/sec ±0.86% (188 runs sampled)
```

## `@material-ui/system`
Expand Down
4 changes: 3 additions & 1 deletion packages/material-ui-benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"dependencies": {
"benchmark": "^2.1.4",
"nodemod": "^1.5.19",
"styled-system": "^3.1.11"
"styled-system": "^3.1.11",
"emotion": "10.0.5",
"emotion-server": "10.0.5"
}
}
225 changes: 76 additions & 149 deletions packages/material-ui-benchmark/src/styles.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-console, no-underscore-dangle */
/* eslint-disable no-console */

import './bootstrap';
import Benchmark from 'benchmark';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import styledComponents, { ServerStyleSheet } from 'styled-components';
import hash from '@emotion/hash';
import styledEmotion from '@emotion/styled';
import { css } from '@emotion/core';
import { renderStylesToString } from 'emotion-server';
import injectSheet, { JssProvider, SheetsRegistry } from 'react-jss';
import { withStyles, makeStyles, StylesProvider } from '@material-ui/styles';
import jss, { getDynamicStyles } from 'jss';
Expand All @@ -19,9 +20,25 @@ const suite = new Benchmark.Suite('styles', {
});
Benchmark.options.minSamples = 100;

global.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true;
const cssContent = `
display: inline-flex;
align-items: center;
justify-content: center;
position: relative;
background-color: transparent;
outline: none;
border: 0;
margin: 0;
border-radius: 0;
padding: 0;
cursor: pointer;
user-select: none;
vertical-align: middle;
-moz-appearance: none;
-webkit-appearance: none;
text-decoration: none`;

const WithStylesButton = withStyles({
const cssObject = {
root: {
display: 'inline-flex',
alignItems: 'center',
Expand All @@ -44,149 +61,34 @@ const WithStylesButton = withStyles({
// system: () => ({
// color: 'blue',
// }),
})(props => <button type="button" className={props.classes.root} {...props} />);
};

const JSSButton = injectSheet({
root: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
WebkitTapHighlightColor: 'transparent',
backgroundColor: 'transparent',
outline: 'none',
border: 0,
margin: 0,
borderRadius: 0,
padding: 0,
cursor: 'pointer',
userSelect: 'none',
verticalAlign: 'middle',
'-moz-appearance': 'none',
'-webkit-appearance': 'none',
textDecoration: 'none',
},
// system: () => ({
// color: 'blue',
// }),
})(props => <button type="button" className={props.classes.root} {...props} />);
const emotionCss = css`
${cssContent}
`;

const useStyles = makeStyles({
root: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
WebkitTapHighlightColor: 'transparent',
backgroundColor: 'transparent',
outline: 'none',
border: 0,
margin: 0,
borderRadius: 0,
padding: 0,
cursor: 'pointer',
userSelect: 'none',
verticalAlign: 'middle',
'-moz-appearance': 'none',
'-webkit-appearance': 'none',
textDecoration: 'none',
},
// system: () => ({
// color: 'blue',
// }),
});
const JSSButton = injectSheet(cssObject)(props => (
<button type="button" className={props.classes.root} {...props} />
));

const WithStylesButton = withStyles(cssObject)(props => (
<button type="submit" className={props.classes.root} {...props} />
));

const EmotionButton = styledEmotion('button')(cssObject.root);

const StyledComponentsButton = styledComponents.button`${cssContent}`;

const useStyles = makeStyles(cssObject);
function HookButton(props) {
const classes = useStyles();
return <button type="button" className={classes.root} {...props} />;
}

const StyledComponentsButton = styledComponents.button`
display: inline-flex;
align-items: center;
justify-content: center;
position: relative;
background-color: transparent;
outline: none;
border: 0;
margin: 0;
border-radius: 0;
padding: 0;
cursor: pointer;
user-select: none;
vertical-align: middle;
-moz-appearance: none;
-webkit-appearance: none;
text-decoration: none;
`;
// ${() => ({
// color: 'blue',
// })}

const EmotionButton = styledEmotion('button')(
{
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
WebkitTapHighlightColor: 'transparent',
backgroundColor: 'transparent',
outline: 'none',
border: 0,
margin: 0,
borderRadius: 0,
padding: 0,
cursor: 'pointer',
userSelect: 'none',
verticalAlign: 'middle',
'-moz-appearance': 'none',
'-webkit-appearance': 'none',
textDecoration: 'none',
},
// () => ({
// color: 'blue',
// }),
);

const rawJSS = () => ({
root: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
WebkitTapHighlightColor: 'transparent',
backgroundColor: 'transparent',
outline: 'none',
border: 0,
margin: 0,
borderRadius: 0,
padding: 0,
cursor: 'pointer',
userSelect: 'none',
verticalAlign: 'middle',
'-moz-appearance': 'none',
'-webkit-appearance': 'none',
textDecoration: 'none',
},
// system: () => ({
// color: 'blue',
// }),
});
const NakedButton = props => <button type="submit" {...props} />;
const EmotionCssButton = props => <button type="submit" css={emotionCss} {...props} />;

suite
.add('JSSButton', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
<JssProvider registry={sheetsRegistry}>
<React.Fragment>
{Array.from(new Array(5)).map((_, index) => (
<JSSButton key={String(index)}>Material-UI</JSSButton>
))}
</React.Fragment>
</JssProvider>,
);
sheetsRegistry.toString();
})
.add('Box', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
Expand All @@ -203,7 +105,7 @@ suite
.add('JSS naked', () => {
const sheetsRegistry = new SheetsRegistry();

const staticStyles = rawJSS();
const staticStyles = cssObject;
const dynamicStyles = getDynamicStyles(staticStyles);

const staticSheet = jss.createStyleSheet(staticStyles);
Expand All @@ -220,13 +122,24 @@ suite
sheetsRegistry.add(dynamicSheet);
}

ReactDOMServer.renderToString(
<JssProvider registry={sheetsRegistry}>
{Array.from(new Array(5)).map((_, index) => (
<button key={String(index)} type="submit">
Material-UI
</button>
))}
</JssProvider>,
);
sheetsRegistry.toString();
})
.add('JSSButton', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
<JssProvider registry={sheetsRegistry}>
<React.Fragment>
{Array.from(new Array(5)).map((_, index) => (
<button key={String(index)} type="submit">
Material-UI
</button>
<JSSButton key={String(index)}>Material-UI</JSSButton>
))}
</React.Fragment>
</JssProvider>,
Expand Down Expand Up @@ -277,20 +190,34 @@ suite
</StylesProvider>,
);
})
.add('Naked', () => {
const Raw = props => <button type="submit" {...props} />;
.add('EmotionCssButton', () => {
ReactDOMServer.renderToString(
<StylesProvider>
<React.Fragment>
{Array.from(new Array(5)).map((_, index) => (
<EmotionCssButton key={String(index)}>Material-UI</EmotionCssButton>
))}
</StylesProvider>,
);
})
.add('EmotionServerCssButton', () => {
renderStylesToString(
ReactDOMServer.renderToString(
<StylesProvider>
{Array.from(new Array(5)).map((_, index) => (
<Raw key={String(index)}>Material-UI</Raw>
<EmotionCssButton key={String(index)}>Material-UI</EmotionCssButton>
))}
</React.Fragment>
</StylesProvider>,
</StylesProvider>,
),
);
})
.add('hashing', () => {
hash(JSON.stringify(rawJSS()));
.add('Naked', () => {
ReactDOMServer.renderToString(
<StylesProvider>
{Array.from(new Array(5)).map((_, index) => (
<NakedButton key={String(index)}>Material-UI</NakedButton>
))}
</StylesProvider>,
);
})
.on('cycle', event => {
console.log(String(event.target));
Expand Down
Loading