Run prettier on scripts/bench (#9671)
This commit is contained in:
parent
e736b4c4b9
commit
f0df495f9a
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Lighthouse = require('lighthouse');
|
const Lighthouse = require('lighthouse');
|
||||||
const ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher.js').ChromeLauncher;
|
const ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher.js')
|
||||||
|
.ChromeLauncher;
|
||||||
const stats = require('stats-analysis');
|
const stats = require('stats-analysis');
|
||||||
const config = require('lighthouse/lighthouse-core/config/perf.json');
|
const config = require('lighthouse/lighthouse-core/config/perf.json');
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
|
@ -14,18 +15,22 @@ function wait(val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runScenario(benchmark, launcher) {
|
async function runScenario(benchmark, launcher) {
|
||||||
const results = await Lighthouse(`http://localhost:8080/${benchmark}/`, {
|
const results = await Lighthouse(
|
||||||
output: 'json',
|
`http://localhost:8080/${benchmark}/`,
|
||||||
disableCpuThrottling: false,
|
{
|
||||||
disableNetworkThrottling: false,
|
output: 'json',
|
||||||
}, config);
|
disableCpuThrottling: false,
|
||||||
|
disableNetworkThrottling: false,
|
||||||
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
const perfMarkings = results.audits['user-timings'].extendedInfo.value;
|
const perfMarkings = results.audits['user-timings'].extendedInfo.value;
|
||||||
const entries = perfMarkings
|
const entries = perfMarkings
|
||||||
.filter(marker => !marker.isMark)
|
.filter(marker => !marker.isMark)
|
||||||
.map(({ duration, name }) => ({
|
.map(({duration, name}) => ({
|
||||||
entry: name,
|
entry: name,
|
||||||
time: duration,
|
time: duration,
|
||||||
}));
|
}));
|
||||||
entries.push({
|
entries.push({
|
||||||
entry: 'First Meaningful Paint',
|
entry: 'First Meaningful Paint',
|
||||||
time: results.audits['first-meaningful-paint'].rawValue,
|
time: results.audits['first-meaningful-paint'].rawValue,
|
||||||
|
@ -55,7 +60,7 @@ function calculateAverages(runs) {
|
||||||
const averages = [];
|
const averages = [];
|
||||||
|
|
||||||
runs.forEach((entries, x) => {
|
runs.forEach((entries, x) => {
|
||||||
entries.forEach(({ entry, time }, i) => {
|
entries.forEach(({entry, time}, i) => {
|
||||||
if (i >= averages.length) {
|
if (i >= averages.length) {
|
||||||
data.push([time]);
|
data.push([time]);
|
||||||
averages.push({
|
averages.push({
|
||||||
|
@ -83,7 +88,7 @@ async function initChrome() {
|
||||||
if (platform === 'linux') {
|
if (platform === 'linux') {
|
||||||
process.env.XVFBARGS = '-screen 0, 1024x768x16';
|
process.env.XVFBARGS = '-screen 0, 1024x768x16';
|
||||||
process.env.LIGHTHOUSE_CHROMIUM_PATH = 'chromium-browser';
|
process.env.LIGHTHOUSE_CHROMIUM_PATH = 'chromium-browser';
|
||||||
const child = spawn('xvfb start', [{ detached: true, stdio: ['ignore'] }]);
|
const child = spawn('xvfb start', [{detached: true, stdio: ['ignore']}]);
|
||||||
child.unref();
|
child.unref();
|
||||||
// wait for chrome to load then continue
|
// wait for chrome to load then continue
|
||||||
await wait(3000);
|
await wait(3000);
|
||||||
|
@ -128,4 +133,3 @@ async function runBenchmark(benchmark, headless) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = runBenchmark;
|
module.exports = runBenchmark;
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,9 @@
|
||||||
const Git = require('nodegit');
|
const Git = require('nodegit');
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
const ncp = require('ncp').ncp;
|
const ncp = require('ncp').ncp;
|
||||||
const {
|
const {existsSync} = require('fs');
|
||||||
existsSync,
|
|
||||||
} = require('fs');
|
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const {
|
const {join} = require('path');
|
||||||
join,
|
|
||||||
} = require('path');
|
|
||||||
|
|
||||||
const reactUrl = 'https://github.com/facebook/react.git';
|
const reactUrl = 'https://github.com/facebook/react.git';
|
||||||
|
|
||||||
|
@ -18,14 +14,16 @@ function cleanDir() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeCommand(command) {
|
function executeCommand(command) {
|
||||||
return new Promise(_resolve => exec(command, (error) => {
|
return new Promise(_resolve =>
|
||||||
if (!error) {
|
exec(command, error => {
|
||||||
_resolve();
|
if (!error) {
|
||||||
} else {
|
_resolve();
|
||||||
console.error(error);
|
} else {
|
||||||
process.exit(1);
|
console.error(error);
|
||||||
}
|
process.exit(1);
|
||||||
}));
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function asyncCopyTo(from, to) {
|
function asyncCopyTo(from, to) {
|
||||||
|
@ -51,9 +49,10 @@ async function buldAllBundles(reactPath = getDefaultReactPath()) {
|
||||||
|
|
||||||
async function buildBenchmark(reactPath = getDefaultReactPath(), benchmark) {
|
async function buildBenchmark(reactPath = getDefaultReactPath(), benchmark) {
|
||||||
// get the build.js from the benchmark directory and execute it
|
// get the build.js from the benchmark directory and execute it
|
||||||
await require(
|
await require(join(__dirname, 'benchmarks', benchmark, 'build.js'))(
|
||||||
join(__dirname, 'benchmarks', benchmark, 'build.js')
|
reactPath,
|
||||||
)(reactPath, asyncCopyTo);
|
asyncCopyTo
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBundleResults(reactPath = getDefaultReactPath()) {
|
function getBundleResults(reactPath = getDefaultReactPath()) {
|
||||||
|
@ -69,7 +68,12 @@ async function getMergeBaseFromLocalGitRepo(localRepo) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildBenchmarkBundlesFromGitRepo(commitId, skipBuild, url = reactUrl, clean) {
|
async function buildBenchmarkBundlesFromGitRepo(
|
||||||
|
commitId,
|
||||||
|
skipBuild,
|
||||||
|
url = reactUrl,
|
||||||
|
clean
|
||||||
|
) {
|
||||||
let repo;
|
let repo;
|
||||||
const remoteRepoDir = getDefaultReactPath();
|
const remoteRepoDir = getDefaultReactPath();
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const {
|
const {readdirSync, statSync} = require('fs');
|
||||||
readdirSync,
|
const {join} = require('path');
|
||||||
statSync,
|
|
||||||
} = require('fs');
|
|
||||||
const { join } = require('path');
|
|
||||||
const runBenchmark = require('./benchmark');
|
const runBenchmark = require('./benchmark');
|
||||||
const {
|
const {
|
||||||
buildAllBundles,
|
buildAllBundles,
|
||||||
|
@ -18,8 +15,8 @@ const printResults = require('./stats');
|
||||||
const serveBenchmark = require('./server');
|
const serveBenchmark = require('./server');
|
||||||
|
|
||||||
function getBenchmarkNames() {
|
function getBenchmarkNames() {
|
||||||
return readdirSync(join(__dirname, 'benchmarks')).filter(
|
return readdirSync(join(__dirname, 'benchmarks')).filter(file =>
|
||||||
file => statSync(join(__dirname, 'benchmarks', file)).isDirectory()
|
statSync(join(__dirname, 'benchmarks', file)).isDirectory()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +40,16 @@ async function runBenchmarks(reactPath) {
|
||||||
const benchmarkName = benchmarkNames[i];
|
const benchmarkName = benchmarkNames[i];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!benchmarkFilter
|
!benchmarkFilter ||
|
||||||
||
|
|
||||||
(benchmarkFilter && benchmarkName.indexOf(benchmarkFilter) !== -1)
|
(benchmarkFilter && benchmarkName.indexOf(benchmarkFilter) !== -1)
|
||||||
) {
|
) {
|
||||||
console.log(chalk.gray(`- Building benchmark "${chalk.white(benchmarkName)}"...`));
|
console.log(
|
||||||
|
chalk.gray(`- Building benchmark "${chalk.white(benchmarkName)}"...`)
|
||||||
|
);
|
||||||
await buildBenchmark(reactPath, benchmarkName);
|
await buildBenchmark(reactPath, benchmarkName);
|
||||||
console.log(chalk.gray(`- Running benchmark "${chalk.white(benchmarkName)}"...`));
|
console.log(
|
||||||
|
chalk.gray(`- Running benchmark "${chalk.white(benchmarkName)}"...`)
|
||||||
|
);
|
||||||
results[benchmarkName] = await runBenchmark(benchmarkName, headless);
|
results[benchmarkName] = await runBenchmark(benchmarkName, headless);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,14 +68,13 @@ async function benchmarkRemoteMaster() {
|
||||||
|
|
||||||
if (!commit || typeof commit !== 'string') {
|
if (!commit || typeof commit !== 'string') {
|
||||||
commit = await getMergeBaseFromLocalGitRepo(join(__dirname, '..', '..'));
|
commit = await getMergeBaseFromLocalGitRepo(join(__dirname, '..', '..'));
|
||||||
console.log(chalk.gray(`- Merge base commit ${chalk.white(commit.tostrS())}`));
|
console.log(
|
||||||
|
chalk.gray(`- Merge base commit ${chalk.white(commit.tostrS())}`)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
// we build the bundles from the React repo
|
// we build the bundles from the React repo
|
||||||
bundles: await buildBenchmarkBundlesFromGitRepo(
|
bundles: await buildBenchmarkBundlesFromGitRepo(commit, skipBuild),
|
||||||
commit,
|
|
||||||
skipBuild
|
|
||||||
),
|
|
||||||
// we use these bundles to run the benchmarks
|
// we use these bundles to run the benchmarks
|
||||||
benchmarks: await runBenchmarks(),
|
benchmarks: await runBenchmarks(),
|
||||||
};
|
};
|
||||||
|
@ -95,8 +94,8 @@ async function benchmarkLocal(reactPath) {
|
||||||
|
|
||||||
async function runLocalBenchmarks(showResults) {
|
async function runLocalBenchmarks(showResults) {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.white.bold('Running benchmarks for ')
|
chalk.white.bold('Running benchmarks for ') +
|
||||||
+ chalk.green.bold('Local (Current Branch)')
|
chalk.green.bold('Local (Current Branch)')
|
||||||
);
|
);
|
||||||
const localResults = await benchmarkLocal(join(__dirname, '..', '..'));
|
const localResults = await benchmarkLocal(join(__dirname, '..', '..'));
|
||||||
|
|
||||||
|
@ -108,8 +107,8 @@ async function runLocalBenchmarks(showResults) {
|
||||||
|
|
||||||
async function runRemoteBenchmarks(showResults) {
|
async function runRemoteBenchmarks(showResults) {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.white.bold('Running benchmarks for ')
|
chalk.white.bold('Running benchmarks for ') +
|
||||||
+ chalk.yellow.bold('Remote (Merge Base)')
|
chalk.yellow.bold('Remote (Merge Base)')
|
||||||
);
|
);
|
||||||
const remoteMasterResults = await benchmarkRemoteMaster();
|
const remoteMasterResults = await benchmarkRemoteMaster();
|
||||||
|
|
||||||
|
@ -121,10 +120,10 @@ async function runRemoteBenchmarks(showResults) {
|
||||||
|
|
||||||
async function compareLocalToMaster() {
|
async function compareLocalToMaster() {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.white.bold('Comparing ')
|
chalk.white.bold('Comparing ') +
|
||||||
+ chalk.green.bold('Local (Current Branch)')
|
chalk.green.bold('Local (Current Branch)') +
|
||||||
+ chalk.white.bold(' to ')
|
chalk.white.bold(' to ') +
|
||||||
+ chalk.yellow.bold('Remote (Merge Base)')
|
chalk.yellow.bold('Remote (Merge Base)')
|
||||||
);
|
);
|
||||||
const localResults = await runLocalBenchmarks(false);
|
const localResults = await runLocalBenchmarks(false);
|
||||||
const remoteMasterResults = await runRemoteBenchmarks(false);
|
const remoteMasterResults = await runRemoteBenchmarks(false);
|
||||||
|
|
|
@ -2,12 +2,8 @@
|
||||||
|
|
||||||
const http2Server = require('http2');
|
const http2Server = require('http2');
|
||||||
const httpServer = require('http-server');
|
const httpServer = require('http-server');
|
||||||
const {
|
const {existsSync, statSync, createReadStream} = require('fs');
|
||||||
existsSync,
|
const {join} = require('path');
|
||||||
statSync,
|
|
||||||
createReadStream,
|
|
||||||
} = require('fs');
|
|
||||||
const { join } = require('path');
|
|
||||||
const argv = require('minimist')(process.argv.slice(2));
|
const argv = require('minimist')(process.argv.slice(2));
|
||||||
const mime = require('mime');
|
const mime = require('mime');
|
||||||
|
|
||||||
|
@ -21,7 +17,12 @@ function sendFile(filename, response) {
|
||||||
|
|
||||||
function createHTTP2Server(benchmark) {
|
function createHTTP2Server(benchmark) {
|
||||||
const server = http2Server.createServer({}, (request, response) => {
|
const server = http2Server.createServer({}, (request, response) => {
|
||||||
const filename = join(__dirname, 'benchmarks', benchmark, request.url).replace(/\?.*/g, '');
|
const filename = join(
|
||||||
|
__dirname,
|
||||||
|
'benchmarks',
|
||||||
|
benchmark,
|
||||||
|
request.url
|
||||||
|
).replace(/\?.*/g, '');
|
||||||
|
|
||||||
if (existsSync(filename) && statSync(filename).isFile()) {
|
if (existsSync(filename) && statSync(filename).isFile()) {
|
||||||
sendFile(filename, response);
|
sendFile(filename, response);
|
||||||
|
|
|
@ -31,20 +31,19 @@ function calculateMeanAndSdOfRatioFromDeltaMethod(
|
||||||
semControl,
|
semControl,
|
||||||
semTest
|
semTest
|
||||||
) {
|
) {
|
||||||
const mean = (
|
const mean =
|
||||||
((meanTest - meanControl) / meanControl) -
|
(meanTest - meanControl) / meanControl -
|
||||||
(Math.pow(semControl, 2) * meanTest / Math.pow(meanControl, 3))
|
Math.pow(semControl, 2) * meanTest / Math.pow(meanControl, 3);
|
||||||
);
|
const variance =
|
||||||
const variance = (
|
|
||||||
Math.pow(semTest / meanControl, 2) +
|
Math.pow(semTest / meanControl, 2) +
|
||||||
(Math.pow(semControl * meanTest, 2) / Math.pow(meanControl, 4))
|
Math.pow(semControl * meanTest, 2) / Math.pow(meanControl, 4);
|
||||||
);
|
|
||||||
return [mean, Math.sqrt(variance)];
|
return [mean, Math.sqrt(variance)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBenchmarkResults(table, localResults, remoteMasterResults) {
|
function addBenchmarkResults(table, localResults, remoteMasterResults) {
|
||||||
const benchmarks = Object.keys(
|
const benchmarks = Object.keys(
|
||||||
(localResults && localResults.benchmarks) || (remoteMasterResults && remoteMasterResults.benchmarks)
|
(localResults && localResults.benchmarks) ||
|
||||||
|
(remoteMasterResults && remoteMasterResults.benchmarks)
|
||||||
);
|
);
|
||||||
benchmarks.forEach(benchmark => {
|
benchmarks.forEach(benchmark => {
|
||||||
const rowHeader = [chalk.white.bold(benchmark)];
|
const rowHeader = [chalk.white.bold(benchmark)];
|
||||||
|
@ -59,15 +58,12 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
|
||||||
}
|
}
|
||||||
table.push(rowHeader);
|
table.push(rowHeader);
|
||||||
|
|
||||||
const measurements = (
|
const measurements =
|
||||||
(localResults && localResults.benchmarks[benchmark].averages)
|
(localResults && localResults.benchmarks[benchmark].averages) ||
|
||||||
||
|
(remoteMasterResults &&
|
||||||
(remoteMasterResults && remoteMasterResults.benchmarks[benchmark].averages)
|
remoteMasterResults.benchmarks[benchmark].averages);
|
||||||
);
|
|
||||||
measurements.forEach((measurement, i) => {
|
measurements.forEach((measurement, i) => {
|
||||||
const row = [
|
const row = [chalk.gray(measurement.entry)];
|
||||||
chalk.gray(measurement.entry),
|
|
||||||
];
|
|
||||||
let remoteMean;
|
let remoteMean;
|
||||||
let remoteSem;
|
let remoteSem;
|
||||||
if (remoteMasterResults) {
|
if (remoteMasterResults) {
|
||||||
|
@ -75,7 +71,9 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
|
||||||
remoteSem = remoteMasterResults.benchmarks[benchmark].averages[i].sem;
|
remoteSem = remoteMasterResults.benchmarks[benchmark].averages[i].sem;
|
||||||
// https://en.wikipedia.org/wiki/1.96 gives a 99% confidence interval.
|
// https://en.wikipedia.org/wiki/1.96 gives a 99% confidence interval.
|
||||||
const ci95 = remoteSem * 1.96;
|
const ci95 = remoteSem * 1.96;
|
||||||
row.push(chalk.white(+remoteMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2)));
|
row.push(
|
||||||
|
chalk.white(+remoteMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let localMean;
|
let localMean;
|
||||||
let localSem;
|
let localSem;
|
||||||
|
@ -83,7 +81,9 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
|
||||||
localMean = localResults.benchmarks[benchmark].averages[i].mean;
|
localMean = localResults.benchmarks[benchmark].averages[i].mean;
|
||||||
localSem = localResults.benchmarks[benchmark].averages[i].sem;
|
localSem = localResults.benchmarks[benchmark].averages[i].sem;
|
||||||
const ci95 = localSem * 1.96;
|
const ci95 = localSem * 1.96;
|
||||||
row.push(chalk.white(+localMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2)));
|
row.push(
|
||||||
|
chalk.white(+localMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (localResults && remoteMasterResults) {
|
if (localResults && remoteMasterResults) {
|
||||||
row.push(percentChange(remoteMean, localMean, remoteSem, localSem));
|
row.push(percentChange(remoteMean, localMean, remoteSem, localSem));
|
||||||
|
@ -107,17 +107,15 @@ function addBundleSizeComparions(table, localResults, remoteMasterResults) {
|
||||||
table.push(bundlesRowHeader);
|
table.push(bundlesRowHeader);
|
||||||
|
|
||||||
const bundles = Object.keys(
|
const bundles = Object.keys(
|
||||||
(localResults && localResults.bundles.bundleSizes)
|
(localResults && localResults.bundles.bundleSizes) ||
|
||||||
||
|
(remoteMasterResults && remoteMasterResults.bundles.bundleSizes)
|
||||||
(remoteMasterResults && remoteMasterResults.bundles.bundleSizes)
|
|
||||||
);
|
);
|
||||||
bundles.forEach(bundle => {
|
bundles.forEach(bundle => {
|
||||||
const row = [
|
const row = [chalk.gray(bundle)];
|
||||||
chalk.gray(bundle),
|
|
||||||
];
|
|
||||||
let remoteSize = 0;
|
let remoteSize = 0;
|
||||||
if (remoteMasterResults) {
|
if (remoteMasterResults) {
|
||||||
const remoteBundle = remoteSize = remoteMasterResults.bundles.bundleSizes[bundle];
|
const remoteBundle = (remoteSize =
|
||||||
|
remoteMasterResults.bundles.bundleSizes[bundle]);
|
||||||
|
|
||||||
if (remoteBundle) {
|
if (remoteBundle) {
|
||||||
remoteSize = remoteSize.size;
|
remoteSize = remoteSize.size;
|
||||||
|
@ -152,7 +150,7 @@ function printResults(localResults, remoteMasterResults) {
|
||||||
if (localResults && remoteMasterResults) {
|
if (localResults && remoteMasterResults) {
|
||||||
head.push('');
|
head.push('');
|
||||||
}
|
}
|
||||||
const table = new Table({ head });
|
const table = new Table({head});
|
||||||
|
|
||||||
addBundleSizeComparions(table, localResults, remoteMasterResults);
|
addBundleSizeComparions(table, localResults, remoteMasterResults);
|
||||||
addBenchmarkResults(table, localResults, remoteMasterResults);
|
addBenchmarkResults(table, localResults, remoteMasterResults);
|
||||||
|
|
|
@ -39,7 +39,7 @@ const config = {
|
||||||
},
|
},
|
||||||
scripts: {
|
scripts: {
|
||||||
patterns: ['scripts/**/*.js'],
|
patterns: ['scripts/**/*.js'],
|
||||||
ignore: ['**/bench/**'],
|
ignore: ['scripts/bench/benchmarks/**'],
|
||||||
options: {
|
options: {
|
||||||
'trailing-comma': 'es5',
|
'trailing-comma': 'es5',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue