-
Notifications
You must be signed in to change notification settings - Fork 48.3k
/
Copy pathrunner.js
135 lines (118 loc) · 3.83 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'use strict';
const {readdirSync, statSync} = require('fs');
const {join} = require('path');
const runBenchmark = require('./benchmark');
const {
buildReactBundles,
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 main (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())}`)
);
}
await buildBenchmarkBundlesFromGitRepo(commit, skipBuild);
return {
benchmarks: await runBenchmarks(),
};
}
// get the performance benchmark results
// of the local react repo
async function benchmarkLocal(reactPath) {
console.log(chalk.gray(`- Building React bundles...`));
await buildReactBundles(reactPath, skipBuild);
return {
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));
}