mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
* Initial commit for WIP benchmarking infrastructure * fixed lint issues and ran prettier * added <rootDir>/scripts/bench/ to ignore paths for Jest * tidied up code and fixed a few bugs in the runner.js * fixed eslint * improved the benchmark output from the runner * fixed typo * tided up print output in runner.js * throw error if chrome canary is not installed on mac * added better bench stats output (tables) * added benchmark diff to table results * adds bundle size comparisons to results * tidied up the results * fixed prettier output * attempt to trigger bech for circleci build * fixes flow exlclusion for lighthouse module * added class components benchmark * cleaned up stats.js * stability changes * circleci node version to 7 * added another benchmark * added colours to the different benchmarks to check if being cached * force no-cache headers * added more info messages * refactor chrome launching. * fixed an issue where launcher.kill might fail * Move server to runner. Launch it only once. * tidy up * changes the logic in how the remote repo is checked out * removes bench from circleci build * removed colors from benchmarks (no longer needed) * added CI integration comment * added hacker news benchmark * added skipBuild functionality * relabelled remote * Add confidence intervals * added first meaningful paint * removed some unused code * reverted code.json * updated benchmark runs back to 10 * no longer breaks when results contain missing bundles * adds CPU throttling * renamed build to remote-repo * small fix to build * fixed bad merge * upped runs to 10 from 2 again * properly pulls master * removes old-bench * runs benchmarks in headless mode * adds a --headless option * improved the git build process * added README * updated based feedback from review * adds merge base commit sha * addressing more PR feedback * remove built JS react files * updated .gitignore * added combined bundle load times to the metrics
141 lines
4.0 KiB
JavaScript
141 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
readdirSync,
|
|
statSync,
|
|
} = require('fs');
|
|
const { join } = require('path');
|
|
const runBenchmark = require('./benchmark');
|
|
const {
|
|
buildAllBundles,
|
|
buildBenchmark,
|
|
buildBenchmarkBundlesFromGitRepo,
|
|
getMergeBaseFromLocalGitRepo,
|
|
} = require('./build');
|
|
const argv = require('minimist')(process.argv.slice(2));
|
|
const chalk = require('chalk');
|
|
const printResults = require('./stats');
|
|
const serveBenchmark = require('./server');
|
|
|
|
function getBenchmarkNames() {
|
|
return readdirSync(join(__dirname, 'benchmarks')).filter(
|
|
file => statSync(join(__dirname, 'benchmarks', file)).isDirectory()
|
|
);
|
|
}
|
|
|
|
function wait(val) {
|
|
return new Promise(resolve => setTimeout(resolve, val));
|
|
}
|
|
|
|
const runRemote = argv.remote;
|
|
const runLocal = argv.local;
|
|
const benchmarkFilter = argv.benchmark;
|
|
const headless = argv.headless;
|
|
const skipBuild = argv['skip-build'];
|
|
|
|
async function runBenchmarks(reactPath) {
|
|
const benchmarkNames = getBenchmarkNames();
|
|
const results = {};
|
|
const server = serveBenchmark();
|
|
await wait(1000);
|
|
|
|
for (let i = 0; i < benchmarkNames.length; i++) {
|
|
const benchmarkName = benchmarkNames[i];
|
|
|
|
if (
|
|
!benchmarkFilter
|
|
||
|
|
(benchmarkFilter && benchmarkName.indexOf(benchmarkFilter) !== -1)
|
|
) {
|
|
console.log(chalk.gray(`- Building benchmark "${chalk.white(benchmarkName)}"...`));
|
|
await buildBenchmark(reactPath, benchmarkName);
|
|
console.log(chalk.gray(`- Running benchmark "${chalk.white(benchmarkName)}"...`));
|
|
results[benchmarkName] = await runBenchmark(benchmarkName, headless);
|
|
}
|
|
}
|
|
|
|
server.close();
|
|
// http-server.close() is async but they don't provide a callback..
|
|
await wait(500);
|
|
return results;
|
|
}
|
|
|
|
// get the performance benchmark results
|
|
// from remote master (default React repo)
|
|
async function benchmarkRemoteMaster() {
|
|
console.log(chalk.gray(`- Building React bundles...`));
|
|
let commit = argv.remote;
|
|
|
|
if (!commit || typeof commit !== 'string') {
|
|
commit = await getMergeBaseFromLocalGitRepo(join(__dirname, '..', '..'));
|
|
console.log(chalk.gray(`- Merge base commit ${chalk.white(commit.tostrS())}`));
|
|
}
|
|
return {
|
|
// we build the bundles from the React repo
|
|
bundles: await buildBenchmarkBundlesFromGitRepo(
|
|
commit,
|
|
skipBuild
|
|
),
|
|
// we use these bundles to run the benchmarks
|
|
benchmarks: await runBenchmarks(),
|
|
};
|
|
}
|
|
|
|
// get the performance benchmark results
|
|
// of the local react repo
|
|
async function benchmarkLocal(reactPath) {
|
|
console.log(chalk.gray(`- Building React bundles...`));
|
|
return {
|
|
// we build the bundles from the React repo
|
|
bundles: await buildAllBundles(reactPath, skipBuild),
|
|
// we use these bundles to run the benchmarks
|
|
benchmarks: await runBenchmarks(reactPath),
|
|
};
|
|
}
|
|
|
|
async function runLocalBenchmarks(showResults) {
|
|
console.log(
|
|
chalk.white.bold('Running benchmarks for ')
|
|
+ chalk.green.bold('Local (Current Branch)')
|
|
);
|
|
const localResults = await benchmarkLocal(join(__dirname, '..', '..'));
|
|
|
|
if (showResults) {
|
|
printResults(localResults, null);
|
|
}
|
|
return localResults;
|
|
}
|
|
|
|
async function runRemoteBenchmarks(showResults) {
|
|
console.log(
|
|
chalk.white.bold('Running benchmarks for ')
|
|
+ chalk.yellow.bold('Remote (Merge Base)')
|
|
);
|
|
const remoteMasterResults = await benchmarkRemoteMaster();
|
|
|
|
if (showResults) {
|
|
printResults(null, remoteMasterResults);
|
|
}
|
|
return remoteMasterResults;
|
|
}
|
|
|
|
async function compareLocalToMaster() {
|
|
console.log(
|
|
chalk.white.bold('Comparing ')
|
|
+ chalk.green.bold('Local (Current Branch)')
|
|
+ chalk.white.bold(' to ')
|
|
+ chalk.yellow.bold('Remote (Merge Base)')
|
|
);
|
|
const localResults = await runLocalBenchmarks(false);
|
|
const remoteMasterResults = await runRemoteBenchmarks(false);
|
|
printResults(localResults, remoteMasterResults);
|
|
}
|
|
|
|
if ((runLocal && runRemote) || (!runLocal && !runRemote)) {
|
|
compareLocalToMaster().then(() => process.exit(0));
|
|
} else if (runLocal) {
|
|
runLocalBenchmarks(true).then(() => process.exit(0));
|
|
} else if (runRemote) {
|
|
runRemoteBenchmarks(true).then(() => process.exit(0));
|
|
}
|