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
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const Table = require('cli-table');
|
|
const filesize = require('filesize');
|
|
const chalk = require('chalk');
|
|
const join = require('path').join;
|
|
const fs = require('fs');
|
|
const prevBuildResults = require('./results.json');
|
|
|
|
const currentBuildResults = {
|
|
// Mutated during the build.
|
|
bundleSizes: Object.assign({}, prevBuildResults.bundleSizes),
|
|
};
|
|
|
|
function saveResults() {
|
|
fs.writeFileSync(
|
|
join('scripts', 'rollup', 'results.json'),
|
|
JSON.stringify(currentBuildResults, null, 2)
|
|
);
|
|
}
|
|
|
|
function percentChange(prev, current) {
|
|
const change = Math.floor((current - prev) / prev * 100);
|
|
|
|
if (change > 0) {
|
|
return chalk.red.bold(`+${change} %`);
|
|
} else if (change <= 0) {
|
|
return chalk.green.bold(change + ' %');
|
|
}
|
|
}
|
|
|
|
function printResults() {
|
|
const table = new Table({
|
|
head: [
|
|
chalk.gray.yellow('Bundle'),
|
|
chalk.gray.yellow('Prev Size'),
|
|
chalk.gray.yellow('Current Size'),
|
|
chalk.gray.yellow('Diff'),
|
|
chalk.gray.yellow('Prev Gzip'),
|
|
chalk.gray.yellow('Current Gzip'),
|
|
chalk.gray.yellow('Diff'),
|
|
],
|
|
});
|
|
Object.keys(currentBuildResults.bundleSizes).forEach(key => {
|
|
const result = currentBuildResults.bundleSizes[key];
|
|
const prev = prevBuildResults.bundleSizes[key];
|
|
if (result === prev) {
|
|
// We didn't rebuild this bundle.
|
|
return;
|
|
}
|
|
|
|
const size = result.size;
|
|
const gzip = result.gzip;
|
|
let prevSize = prev ? prev.size : 0;
|
|
let prevGzip = prev ? prev.gzip : 0;
|
|
table.push([
|
|
chalk.white.bold(key),
|
|
chalk.gray.bold(filesize(prevSize)),
|
|
chalk.white.bold(filesize(size)),
|
|
percentChange(prevSize, size),
|
|
chalk.gray.bold(filesize(prevGzip)),
|
|
chalk.white.bold(filesize(gzip)),
|
|
percentChange(prevGzip, gzip),
|
|
]);
|
|
});
|
|
return table.toString();
|
|
}
|
|
|
|
module.exports = {
|
|
printResults,
|
|
saveResults,
|
|
currentBuildResults,
|
|
};
|