Skip to content

Commit

Permalink
Merge pull request #10 from oliviertassinari/sub-ms
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored Oct 12, 2020
2 parents 60aa699 + 0a835ef commit da8bf24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
31 changes: 30 additions & 1 deletion benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';

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

const Component = requirePerfScenarios(scenarioSuitePath).default;

ReactDOM.render(<Component />, rootEl);
const start = performance.now();
let end;

function TestCase(props) {
const ref = React.useRef(null);

React.useLayoutEffect(() => {
// Force layout
ref.current.getBoundingClientRect();

end = performance.now();
window.timing = {
render: end - start,
};
});

return <div ref={ref}>{props.children}</div>;
}

TestCase.propTypes = {
children: PropTypes.node,
};

ReactDOM.render(
<TestCase>
<Component />
</TestCase>,
rootEl,
);
7 changes: 3 additions & 4 deletions benchmark/scripts/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
/* eslint-disable no-await-in-loop */
const puppeteer = require('puppeteer');
const { performance } = require('perf_hooks');
const handler = require('serve-handler');
const http = require('http');

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

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

const benchmark = await page.evaluate(() => {
const { loadEventEnd, navigationStart } = performance.timing;
return loadEventEnd - navigationStart;
return window.timing.render;
});

measures.push(benchmark);
Expand Down

0 comments on commit da8bf24

Please sign in to comment.