Skip to content

Commit da8bf24

Browse files
authored
Merge pull request #10 from oliviertassinari/sub-ms
2 parents 60aa699 + 0a835ef commit da8bf24

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

benchmark/index.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3+
import PropTypes from 'prop-types';
34

45
// Get all the scenarios
56
const requirePerfScenarios = require.context('./scenarios', true, /(js|ts|tsx)$/);
@@ -10,4 +11,32 @@ const scenarioSuitePath = window.location.search.replace('?', '');
1011

1112
const Component = requirePerfScenarios(scenarioSuitePath).default;
1213

13-
ReactDOM.render(<Component />, rootEl);
14+
const start = performance.now();
15+
let end;
16+
17+
function TestCase(props) {
18+
const ref = React.useRef(null);
19+
20+
React.useLayoutEffect(() => {
21+
// Force layout
22+
ref.current.getBoundingClientRect();
23+
24+
end = performance.now();
25+
window.timing = {
26+
render: end - start,
27+
};
28+
});
29+
30+
return <div ref={ref}>{props.children}</div>;
31+
}
32+
33+
TestCase.propTypes = {
34+
children: PropTypes.node,
35+
};
36+
37+
ReactDOM.render(
38+
<TestCase>
39+
<Component />
40+
</TestCase>,
41+
rootEl,
42+
);

benchmark/scripts/benchmark.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-console */
22
/* eslint-disable no-await-in-loop */
33
const puppeteer = require('puppeteer');
4-
const { performance } = require('perf_hooks');
54
const handler = require('serve-handler');
65
const http = require('http');
76

@@ -76,11 +75,11 @@ async function runMeasures(browser, testCaseName, testCase, times) {
7675
const measures = [];
7776

7877
for (let i = 0; i < times; i += 1) {
79-
const page = await browser.openPage(`http://localhost:${PORT}/${APP}?${testCase}`);
78+
const url = `http://localhost:${PORT}/${APP}?${testCase}`;
79+
const page = await browser.openPage(url);
8080

8181
const benchmark = await page.evaluate(() => {
82-
const { loadEventEnd, navigationStart } = performance.timing;
83-
return loadEventEnd - navigationStart;
82+
return window.timing.render;
8483
});
8584

8685
measures.push(benchmark);

0 commit comments

Comments
 (0)