mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 10:07:35 +00:00
Add unregistered styles benchmark
This commit is contained in:
@@ -56,8 +56,8 @@ const benchmark = ({ name, description, setup, teardown, task, runs }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
console.group();
|
console.group(`[benchmark] ${name}`);
|
||||||
console.log(`[benchmark] ${name}: ${description}`);
|
console.log(description);
|
||||||
window.requestAnimationFrame(a);
|
window.requestAnimationFrame(a);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
|
||||||
const createDeepTree = ({ StyleSheet, View }) => {
|
const createDeepTree = ({ StyleSheet, View }, options = {}) => {
|
||||||
class DeepTree extends Component {
|
class DeepTree extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
breadth: PropTypes.number.isRequired,
|
breadth: PropTypes.number.isRequired,
|
||||||
@@ -11,6 +11,7 @@ const createDeepTree = ({ StyleSheet, View }) => {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { breadth, depth, id, wrap } = this.props;
|
const { breadth, depth, id, wrap } = this.props;
|
||||||
|
|
||||||
let result = (
|
let result = (
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
@@ -45,7 +46,7 @@ const createDeepTree = ({ StyleSheet, View }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const stylesObject = {
|
||||||
outer: {
|
outer: {
|
||||||
padding: 4
|
padding: 4
|
||||||
},
|
},
|
||||||
@@ -77,7 +78,9 @@ const createDeepTree = ({ StyleSheet, View }) => {
|
|||||||
terminal2: {
|
terminal2: {
|
||||||
backgroundColor: 'red'
|
backgroundColor: 'red'
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const styles = options.registerStyles ? StyleSheet.create(stylesObject) : stylesObject;
|
||||||
|
|
||||||
return DeepTree;
|
return DeepTree;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import React from 'react';
|
|||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import ReactNative from 'react-native';
|
import ReactNative from 'react-native';
|
||||||
|
|
||||||
// React Native for Web implementation of the tree
|
const deepTreeBenchmark = ({ breadth, depth, registerStyles = true, runs, wrap }, node) => () => {
|
||||||
const DeepTree = createDeepTree(ReactNative);
|
// React Native for Web implementation of the tree
|
||||||
|
const DeepTree = createDeepTree(ReactNative, { registerStyles });
|
||||||
|
|
||||||
const deepTreeBenchmark = ({ breadth, depth, wrap, runs }, node) => () => {
|
const setup = () => {};
|
||||||
const setup = () => { };
|
|
||||||
const teardown = () => ReactDOM.unmountComponentAtNode(node);
|
const teardown = () => ReactDOM.unmountComponentAtNode(node);
|
||||||
|
|
||||||
return benchmark({
|
return benchmark({
|
||||||
name: 'DeepTree',
|
name: `DeepTree (${registerStyles ? 'registered' : 'unregistered'}) styles)`,
|
||||||
description: `depth=${depth}, breadth=${breadth}, wrap=${wrap})`,
|
description: `depth=${depth}, breadth=${breadth}, wrap=${wrap}`,
|
||||||
runs,
|
runs,
|
||||||
setup,
|
setup,
|
||||||
teardown,
|
teardown,
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
|
import createDeepTree from './benchmarks/deepTree/createDeepTree';
|
||||||
import deepTree from './benchmarks/deepTree';
|
import deepTree from './benchmarks/deepTree';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
import ReactNative from 'react-native';
|
||||||
|
|
||||||
const node = document.querySelector('.root');
|
const node = document.querySelector('.root');
|
||||||
|
const DeepTree = createDeepTree(ReactNative);
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
|
.then(deepTree({ wrap: 4, depth: 3, breadth: 10, runs: 10, registerStyles: false }, node))
|
||||||
|
.then(deepTree({ wrap: 1, depth: 5, breadth: 3, runs: 20, registerStyles: false }, node))
|
||||||
.then(deepTree({ wrap: 4, depth: 3, breadth: 10, runs: 10 }, node))
|
.then(deepTree({ wrap: 4, depth: 3, breadth: 10, runs: 10 }, node))
|
||||||
.then(deepTree({ wrap: 1, depth: 5, breadth: 3, runs: 20 }, node))
|
.then(deepTree({ wrap: 1, depth: 5, breadth: 3, runs: 20 }, node))
|
||||||
.then(() => ReactDOM.render(<div>Complete</div>, node));
|
.then(() => ReactDOM.render(<DeepTree breadth={3} depth={5} id={0} wrap={1} />, node));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user