Perf Test for the propTypes change.
cpojer committed
Jan 17, 2014 at 10:28 UTC
8b12670ef9f8a4567b1b0aac088b325759ad3916
3 files changed
+89
-5
perf/index.html
+1
@@ -29,6 +29,7 @@ var tests = [
29
"setState-callback.js",
30
"basic-div.js",
31
"basic-unmount.js",
32
+ "propTypes.js",
33
"renderComponent-basic.js",
34
"shouldComponentUpdate.js",
35
];
perf/tests/propTypes.js
new
+85
@@ -0,0 +1,85 @@
1
+if (typeof exports == 'undefined') exports = {};
2
+
3
+/*http://benchmarkjs.com/docs#options*/
4
+
5
+exports.name = 'propTypes';
6
+
7
+var Thing = function() {};
8
+var List;
9
+var ListItem;
10
+var MyReactComponent;
11
+var _rootNode;
12
+
13
+exports.setup = function(){
14
+ List = React.createClass({
15
+ propTypes: {
16
+ array: React.PropTypes.array,
17
+ bool: React.PropTypes.bool.isRequired,
18
+ number: React.PropTypes.number,
19
+ string: React.PropTypes.string.isRequired,
20
+ func: React.PropTypes.func.isRequired,
21
+ renderable: React.PropTypes.renderable.isRequired,
22
+ instanceOf: React.PropTypes.instanceOf(Thing).isRequired
23
+ },
24
+ render: function() {
25
+ return React.DOM.ul(null, this.props.children);
26
+ }
27
+ });
28
+
29
+ ListItem = React.createClass({
30
+ propTypes: {
31
+ array: React.PropTypes.array,
32
+ bool: React.PropTypes.bool.isRequired,
33
+ number: React.PropTypes.number,
34
+ string: React.PropTypes.string.isRequired,
35
+ func: React.PropTypes.func.isRequired,
36
+ renderable: React.PropTypes.renderable.isRequired,
37
+ renderable2: React.PropTypes.renderable.isRequired,
38
+ instanceOf: React.PropTypes.instanceOf(Thing).isRequired,
39
+ component: React.PropTypes.component.isRequired
40
+ },
41
+ render: function(){
42
+ return React.DOM.li(null,
43
+ this.props.number + this.props.string + this.props.renderable
44
+ );
45
+ }
46
+ });
47
+
48
+ MyReactComponent = React.createClass({
49
+ render: function() {
50
+ return React.DOM.span();
51
+ }
52
+ });
53
+
54
+ _rootNode = document.createElement('div');
55
+ document.body.appendChild(_rootNode);
56
+};
57
+exports.fn = function(){
58
+ var items = [];
59
+ for (var i = 0; i < 1000; i++) {
60
+ items.push(ListItem({
61
+ array: [11, 12, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
62
+ bool: false,
63
+ number: Math.random(),
64
+ string: 'banana banana banana',
65
+ func: function() { return 'this is a function'; },
66
+ renderable: 'renderable string',
67
+ renderable2: [MyReactComponent(), 'a string'],
68
+ instanceOf: new Thing,
69
+ component: MyReactComponent()
70
+ }));
71
+ };
72
+
73
+ React.renderComponent(List({
74
+ array: [11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
75
+ bool: false,
76
+ number: Math.random(),
77
+ string: 'banana banana banana',
78
+ func: function() { return 'this is a function'; },
79
+ renderable: 'renderable string',
80
+ instanceOf: new Thing
81
+ }, items), _rootNode);
82
+};
83
+exports.teardown = function(){
84
+ React.unmountComponentAtNode(_rootNode);
85
+};
src/vendor/core/warning.js
+3
-5
@@ -26,16 +26,14 @@
26
function warning(condition, format, ...args) {
27
if (format === undefined) {
28
throw new Error(
29
- '`warning(condition, format, ...args)` requires an error message argument'
29
+ '`warning(condition, format, ...args)` requires a warning ' +
30
+ 'message argument'
31
);
32
}
33
34
if (!condition) {
35
var argIndex = 0;
35
- console.warn(
36
- 'Warning: ' +
37
- format.replace(/%s/g, () => args[argIndex++])
38
- );
36
+ console.warn('Warning: ' + format.replace(/%s/g, () => args[argIndex++]));
37
}
38
}
39