@samitouri / QOS-React / commits / 8540768616

Fix benchmark runner (#11749)

Dan Abramov committed Dec 2, 2017 at 00:00 UTC 8540768616861e513010ea2874a3188098105cca
4 files changed +21 -84
scripts/bench/README.md
+12 -12
@@ -4,10 +4,10 @@
4
5 In most cases, the only two commands you might want to use are:
6
7 -- `yarn bench`
8 -- `yarn build -- --type=UMD_PROD && yarn bench -- --skip-build`
7 +- `yarn start`
8 +- `yarn build core,dom-client --type=UMD_PROD && yarn start --skip-build`
9
10 -The first command will run benchmarks with all the default settings. A local and remote build will occcur on all bundles, both local and remote repos will be run against all benchmarks.
10 +The first command will run benchmarks with all the default settings. A local and remote build will occur on React and ReactDOM UMD bundles, both local and remote repos will be run against all benchmarks.
11
12 The second command will run all benchmarks but skip the build process. This is useful for when doing local performance tweaking and the remote repo has already had its bundles built. Both local and remote repos will be run against all benchmarks with this command too.
13
@@ -15,27 +15,27 @@ The other commands are as follows:
15
16 ```bash
17 # will compare local repo vs remote merge base repo
18 -yarn bench
18 +yarn start
19
20 # will compare local repo vs remote merge base repo
21 # this can significantly improve bench times due to no build
22 -yarn bench -- --skip-build
22 +yarn start --skip-build
23
24 # will only build and run local repo against benchmarks (no remote values will be shown)
25 -yarn bench -- --local
25 +yarn start --local
26
27 # will only build and run remote merge base repo against benchmarks (no local values will be shown)
28 -yarn bench -- --remote
28 +yarn start --remote
29
30 # will only build and run remote master repo against benchmarks
31 -yarn bench -- --remote=master
31 +yarn start --remote=master
32
33 -# same as "yarn bench"
34 -yarn bench -- --remote --local
33 +# same as "yarn start"
34 +yarn start --remote --local
35
36 # runs benchmarks with Chrome in headless mode
37 -yarn bench -- --headless
37 +yarn start --headless
38
39 # runs only specific string matching benchmarks
40 -yarn bench -- --benchmark=hacker
40 +yarn start --benchmark=hacker
41 ```
\ No newline at end of file
scripts/bench/build.js
+6 -16
@@ -42,11 +42,6 @@ function getDefaultReactPath() {
42 return join(__dirname, 'remote-repo');
43 }
44
45 -async function buldAllBundles(reactPath = getDefaultReactPath()) {
46 - // build the react FB bundles in the build
47 - await executeCommand(`cd ${reactPath} && yarn && yarn build`);
48 -}
49 -
45 async function buildBenchmark(reactPath = getDefaultReactPath(), benchmark) {
46 // get the build.js from the benchmark directory and execute it
47 await require(join(__dirname, 'benchmarks', benchmark, 'build.js'))(
@@ -55,10 +50,6 @@ async function buildBenchmark(reactPath = getDefaultReactPath(), benchmark) {
50 );
51 }
52
58 -function getBundleResults(reactPath = getDefaultReactPath()) {
59 - return require(join(reactPath, 'scripts', 'rollup', 'results.json'));
60 -}
61 -
53 async function getMergeBaseFromLocalGitRepo(localRepo) {
54 const repo = await Git.Repository.open(localRepo);
55 return await Git.Merge.base(
@@ -106,17 +97,16 @@ async function buildBenchmarkBundlesFromGitRepo(
97 // then we checkout the merge base
98 await Git.Checkout.tree(repo, commit);
99 }
109 - await buildAllBundles();
100 + await buildReactBundles();
101 }
111 - return getBundleResults();
102 }
103
114 -async function buildAllBundles(reactPath, skipBuild) {
104 +async function buildReactBundles(reactPath = getDefaultReactPath(), skipBuild) {
105 if (!skipBuild) {
116 - // build all bundles so we can get all stats and use bundles for benchmarks
117 - await buldAllBundles(reactPath);
106 + await executeCommand(
107 + `cd ${reactPath} && yarn && yarn build core,dom-client --type=UMD_PROD`
108 + );
109 }
119 - return getBundleResults(reactPath);
110 }
111
112 // if run directly via CLI
@@ -125,7 +115,7 @@ if (require.main === module) {
115 }
116
117 module.exports = {
128 - buildAllBundles,
118 + buildReactBundles,
119 buildBenchmark,
120 buildBenchmarkBundlesFromGitRepo,
121 getMergeBaseFromLocalGitRepo,
scripts/bench/runner.js
+3 -7
@@ -4,7 +4,7 @@ const {readdirSync, statSync} = require('fs');
4 const {join} = require('path');
5 const runBenchmark = require('./benchmark');
6 const {
7 - buildAllBundles,
7 + buildReactBundles,
8 buildBenchmark,
9 buildBenchmarkBundlesFromGitRepo,
10 getMergeBaseFromLocalGitRepo,
@@ -72,10 +72,8 @@ async function benchmarkRemoteMaster() {
72 chalk.gray(`- Merge base commit ${chalk.white(commit.tostrS())}`)
73 );
74 }
75 + await buildBenchmarkBundlesFromGitRepo(commit, skipBuild);
76 return {
76 - // we build the bundles from the React repo
77 - bundles: await buildBenchmarkBundlesFromGitRepo(commit, skipBuild),
78 - // we use these bundles to run the benchmarks
77 benchmarks: await runBenchmarks(),
78 };
79 }
@@ -84,10 +82,8 @@ async function benchmarkRemoteMaster() {
82 // of the local react repo
83 async function benchmarkLocal(reactPath) {
84 console.log(chalk.gray(`- Building React bundles...`));
85 + await buildReactBundles(reactPath, skipBuild);
86 return {
88 - // we build the bundles from the React repo
89 - bundles: await buildAllBundles(reactPath, skipBuild),
90 - // we use these bundles to run the benchmarks
87 benchmarks: await runBenchmarks(reactPath),
88 };
89 }
scripts/bench/stats.js
-49
@@ -93,52 +93,6 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
93 });
94 }
95
96 -function addBundleSizeComparsions(table, localResults, remoteMasterResults) {
97 - const bundlesRowHeader = [chalk.white.bold('Bundles')];
98 - if (remoteMasterResults) {
99 - bundlesRowHeader.push(chalk.white.bold('Size'));
100 - }
101 - if (localResults) {
102 - bundlesRowHeader.push(chalk.white.bold('Size'));
103 - }
104 - if (localResults && remoteMasterResults) {
105 - bundlesRowHeader.push(chalk.white.bold('Diff'));
106 - }
107 - table.push(bundlesRowHeader);
108 -
109 - const bundles = Object.keys(
110 - (localResults && localResults.bundles.bundleSizes) ||
111 - (remoteMasterResults && remoteMasterResults.bundles.bundleSizes)
112 - );
113 - bundles.forEach(bundle => {
114 - const row = [chalk.gray(bundle)];
115 - let remoteSize = 0;
116 - if (remoteMasterResults) {
117 - const remoteBundle = (remoteSize =
118 - remoteMasterResults.bundles.bundleSizes[bundle]);
119 -
120 - if (remoteBundle) {
121 - remoteSize = remoteSize.size;
122 - }
123 - row.push(chalk.white(remoteSize + ' kb'));
124 - }
125 - let localSize = 0;
126 - if (localResults) {
127 - const localBundle = localResults.bundles.bundleSizes[bundle];
128 -
129 - if (localBundle) {
130 - localSize = localBundle.size;
131 - }
132 - localSize = localResults.bundles.bundleSizes[bundle].size;
133 - row.push(chalk.white(localSize + ' kb'));
134 - }
135 - if (localResults && remoteMasterResults) {
136 - row.push(percentChange(remoteSize, localSize, 0, 0));
137 - }
138 - table.push(row);
139 - });
140 -}
141 -
96 function printResults(localResults, remoteMasterResults) {
97 const head = [''];
98 if (remoteMasterResults) {
@@ -151,10 +105,7 @@ function printResults(localResults, remoteMasterResults) {
105 head.push('');
106 }
107 const table = new Table({head});
154 -
155 - addBundleSizeComparsions(table, localResults, remoteMasterResults);
108 addBenchmarkResults(table, localResults, remoteMasterResults);
157 -
109 console.log(table.toString());
110 }
111