-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
49 lines (37 loc) · 1.17 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react';
import {render} from 'react-dom';
import Stats from 'stats.js';
// import {whyDidYouUpdate} from 'why-did-you-update';
//
// if (process.env.NODE_ENV !== 'production') {
// whyDidYouUpdate(React);
// }
const {document, addEventListener, requestAnimationFrame} = global;
let badProps = false;
const label = document.createElement('label');
label.innerHTML = ' Bad props';
label.style.cssText = 'position: fixed; top: 0; right: 90px;';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = badProps;
checkbox.onclick = () => {
badProps = checkbox.checked;
};
label.insertBefore(checkbox, label.firstChild);
const stats = new Stats();
stats.dom.style.left = null;
stats.dom.style.right = 0;
const reference = {};
export default renderer => {
addEventListener('load', () => {
const container = document.getElementById('container');
[stats.dom, label].forEach(el => document.body.appendChild(el));
const animate = () => {
stats.begin();
render(renderer(badProps), container);
stats.end();
requestAnimationFrame(animate);
};
requestAnimationFrame(animate);
}, false);
};