Last active
July 11, 2017 17:23
-
-
Save alexesDev/064f987e750dcba0b07c7eb22ad5ec4c to your computer and use it in GitHub Desktop.
styled-components (300ms) vs plain className (100ms)
This file contains hidden or 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
| <style type="text/css"> | |
| .block { | |
| border: 1px solid red; | |
| min-height: 1px; | |
| } | |
| </style> | |
| <div id="mount"></div> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/styled-components/2.1.1/styled-components.min.js"></script> | |
| <script> | |
| var Block = styled.default.div` | |
| border: 1px solid red; | |
| min-height: 1px; | |
| `; | |
| var Plain = function(props) { | |
| return React.createElement('div', Object.assign({}, props, { | |
| className: 'block', | |
| })); | |
| }; | |
| var data = Array.apply(null, new Array(1000)); | |
| var makeComplexComponent = function(Base) { | |
| var ComplexContent = function() { | |
| return React.createElement(Base, null, [ | |
| React.createElement(Base, null, [ | |
| React.createElement(Base), | |
| React.createElement(Base), | |
| React.createElement(Base), | |
| ]), | |
| React.createElement(Base, null, [ | |
| React.createElement(Base), | |
| React.createElement(Base), | |
| React.createElement(Base), | |
| ]), | |
| ]); | |
| } | |
| return function(props) { | |
| return React.createElement('div', null, [ | |
| props.type, | |
| data.map(function() { | |
| return React.createElement(ComplexContent); | |
| }) | |
| ]); | |
| }; | |
| }; | |
| var StyledComponent = makeComplexComponent(Block); | |
| var PlainComponent = makeComplexComponent(Plain); | |
| var type = location.hash; | |
| var CurrentComponent = location.hash === '#plain' ? PlainComponent : StyledComponent; | |
| location.hash = location.hash === '#plain' ? '#styled' : '#plain'; | |
| console.time('render'); | |
| ReactDOM.render(React.createElement(CurrentComponent, { type: type }), document.getElementById('mount')); | |
| console.timeEnd('render'); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment