Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Benchmark Material-UI (#13233)
- Loading branch information
1 parent
77da649
commit 7d6ac7f
Showing
13 changed files
with
283 additions
and
38 deletions.
There are no files selected for viewing
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
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,14 @@ | ||
# Material-UI Benchmarking | ||
|
||
```sh | ||
yarn benchmark | ||
|
||
ButtonBase x 78,875 ops/sec ±11.38% (80 runs sampled) | ||
Grid x 84,284 ops/sec ±2.36% (87 runs sampled) | ||
JssButton x 253,054 ops/sec ±4.50% (83 runs sampled) | ||
StyledComponents x 110,824 ops/sec ±0.79% (92 runs sampled) | ||
Emotion x 119,230 ops/sec ±1.81% (89 runs sampled) | ||
Button x 27,616 ops/sec ±3.85% (85 runs sampled) | ||
ButtonBase disableRipple x 85,133 ops/sec ±2.25% (84 runs sampled) | ||
button x 993,210 ops/sec ±4.82% (81 runs sampled) | ||
``` |
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 @@ | ||
{ | ||
"name": "@material-ui/benchmark", | ||
"private": true, | ||
"version": "3.0.0", | ||
"description": "Material-UI Benchmark.", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mui-org/material-ui.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mui-org/material-ui/issues" | ||
}, | ||
"homepage": "https://github.com/mui-org/material-ui/tree/master/packages/material-ui-benchmark", | ||
"scripts": { | ||
"benchmark": "cd ../../ && NODE_ENV=production BABEL_ENV=docs-production babel-node packages/material-ui-benchmark/src/benchmark.js" | ||
}, | ||
"devDependencies": {}, | ||
"engines": { | ||
"node": ">=6.0.0" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"benchmark": "^2.1.4", | ||
"emotion": "^9.2.12", | ||
"nodemod": "^1.5.19", | ||
"react-emotion": "^9.2.12", | ||
"styled-components": "^3.4.10" | ||
} | ||
} |
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,98 @@ | ||
/* eslint-disable no-console, no-underscore-dangle */ | ||
|
||
import Benchmark from 'benchmark'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import styled2 from 'react-emotion'; | ||
import Button from '@material-ui/core/Button'; | ||
import Grid from '@material-ui/core/Grid'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import ButtonBase from '@material-ui/core/ButtonBase'; | ||
|
||
const suite = new Benchmark.Suite({ | ||
async: true, | ||
minSamples: 100, | ||
minTime: 5, | ||
}); | ||
|
||
global.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true; | ||
|
||
function CustomButton() { | ||
return <button type="button">Material-UI</button>; | ||
} | ||
|
||
const JssButton = withStyles({ | ||
root: { | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
position: 'relative', | ||
// Remove grey highlight | ||
WebkitTapHighlightColor: 'transparent', | ||
backgroundColor: 'transparent', // Reset default value | ||
// We disable the focus ring for mouse, touch and keyboard users. | ||
outline: 'none', | ||
border: 0, | ||
margin: 0, // Remove the margin in Safari | ||
borderRadius: 0, | ||
padding: 0, // Remove the padding in Firefox | ||
cursor: 'pointer', | ||
userSelect: 'none', | ||
verticalAlign: 'middle', | ||
'-moz-appearance': 'none', // Reset | ||
'-webkit-appearance': 'none', // Reset | ||
textDecoration: 'none', | ||
// So we take precedent over the style of a native <a /> element. | ||
color: 'inherit', | ||
'&::-moz-focus-inner': { | ||
borderStyle: 'none', // Remove Firefox dotted outline. | ||
}, | ||
'&$disabled': { | ||
pointerEvents: 'none', // Disable link interactions | ||
cursor: 'default', | ||
}, | ||
}, | ||
})(({ classes, ...other }) => <button type="button" {...other} />); | ||
|
||
const StyledComponents = styled.button` | ||
font-size: 1.5em; | ||
text-align: center; | ||
color: palevioletred; | ||
`; | ||
|
||
const Emotion = styled2('button')` | ||
font-size: 1.5em; | ||
text-align: center; | ||
color: palevioletred; | ||
`; | ||
|
||
suite | ||
.add('ButtonBase', () => { | ||
ReactDOMServer.renderToString(<ButtonBase>Material-UI</ButtonBase>); | ||
}) | ||
.add('Grid', () => { | ||
ReactDOMServer.renderToString(<Grid>Material-UI</Grid>); | ||
}) | ||
.add('JssButton', () => { | ||
ReactDOMServer.renderToString(<JssButton>Material-UI</JssButton>); | ||
}) | ||
.add('StyledComponents', () => { | ||
ReactDOMServer.renderToString(<StyledComponents>Material-UI</StyledComponents>); | ||
}) | ||
.add('Emotion', () => { | ||
ReactDOMServer.renderToString(<Emotion>Material-UI</Emotion>); | ||
}) | ||
.add('Button', () => { | ||
ReactDOMServer.renderToString(<Button>Material-UI</Button>); | ||
}) | ||
.add('ButtonBase disableRipple', () => { | ||
ReactDOMServer.renderToString(<ButtonBase disableRipple>Material-UI</ButtonBase>); | ||
}) | ||
.add('button', () => { | ||
ReactDOMServer.renderToString(<CustomButton />); | ||
}) | ||
.on('cycle', event => { | ||
console.log(String(event.target)); | ||
}) | ||
.run(); |
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
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
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
47 changes: 26 additions & 21 deletions
47
packages/material-ui/src/ButtonBase/createRippleHandler.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 |
---|---|---|
@@ -1,30 +1,35 @@ | ||
function createRippleHandler(instance, eventName, action, cb) { | ||
return function handleEvent(event) { | ||
if (cb) { | ||
cb.call(instance, event); | ||
} | ||
/* eslint-disable import/no-mutable-exports */ | ||
|
||
let ignore = false; | ||
let createRippleHandler = (instance, eventName, action, cb) => event => { | ||
if (cb) { | ||
cb.call(instance, event); | ||
} | ||
|
||
// Ignore events that have been `event.preventDefault()` marked. | ||
if (event.defaultPrevented) { | ||
ignore = true; | ||
} | ||
let ignore = false; | ||
|
||
if (instance.props.disableTouchRipple && eventName !== 'Blur') { | ||
ignore = true; | ||
} | ||
// Ignore events that have been `event.preventDefault()` marked. | ||
if (event.defaultPrevented) { | ||
ignore = true; | ||
} | ||
|
||
if (!ignore && instance.ripple) { | ||
instance.ripple[action](event); | ||
} | ||
if (instance.props.disableTouchRipple && eventName !== 'Blur') { | ||
ignore = true; | ||
} | ||
|
||
if (typeof instance.props[`on${eventName}`] === 'function') { | ||
instance.props[`on${eventName}`](event); | ||
} | ||
if (!ignore && instance.ripple) { | ||
instance.ripple[action](event); | ||
} | ||
|
||
return true; | ||
}; | ||
if (typeof instance.props[`on${eventName}`] === 'function') { | ||
instance.props[`on${eventName}`](event); | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
/* istanbul ignore if */ | ||
if (!process.browser) { | ||
createRippleHandler = () => () => {}; | ||
} | ||
|
||
export default createRippleHandler; |
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
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
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
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
Oops, something went wrong.