Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have sub millisecond measurments #10

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
);
8 changes: 4 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,12 @@ 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);
// console.log('url', url)
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

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

measures.push(benchmark);
Expand Down