Run prettier on scripts/bench (#9671)
Ben Alpert committed
May 11, 2017 at 16:14 UTC
f0df495f9a97c0f24a3c20761244dab7da99bd77
6 files changed
+96
-90
scripts/bench/benchmark.js
+18
-14
@@ -1,7 +1,8 @@
1
'use strict';
2
3
const Lighthouse = require('lighthouse');
4
-const ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher.js').ChromeLauncher;
4
+const ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher.js')
5
+ .ChromeLauncher;
6
const stats = require('stats-analysis');
7
const config = require('lighthouse/lighthouse-core/config/perf.json');
8
const spawn = require('child_process').spawn;
@@ -14,18 +15,22 @@ function wait(val) {
15
}
16
17
async function runScenario(benchmark, launcher) {
17
- const results = await Lighthouse(`http://localhost:8080/${benchmark}/`, {
18
- output: 'json',
19
- disableCpuThrottling: false,
20
- disableNetworkThrottling: false,
21
- }, config);
18
+ const results = await Lighthouse(
19
+ `http://localhost:8080/${benchmark}/`,
20
+ {
21
+ output: 'json',
22
+ disableCpuThrottling: false,
23
+ disableNetworkThrottling: false,
24
+ },
25
+ config
26
+ );
27
const perfMarkings = results.audits['user-timings'].extendedInfo.value;
28
const entries = perfMarkings
24
- .filter(marker => !marker.isMark)
25
- .map(({ duration, name }) => ({
26
- entry: name,
27
- time: duration,
28
- }));
29
+ .filter(marker => !marker.isMark)
30
+ .map(({duration, name}) => ({
31
+ entry: name,
32
+ time: duration,
33
+ }));
34
entries.push({
35
entry: 'First Meaningful Paint',
36
time: results.audits['first-meaningful-paint'].rawValue,
@@ -55,7 +60,7 @@ function calculateAverages(runs) {
60
const averages = [];
61
62
runs.forEach((entries, x) => {
58
- entries.forEach(({ entry, time }, i) => {
63
+ entries.forEach(({entry, time}, i) => {
64
if (i >= averages.length) {
65
data.push([time]);
66
averages.push({
@@ -83,7 +88,7 @@ async function initChrome() {
88
if (platform === 'linux') {
89
process.env.XVFBARGS = '-screen 0, 1024x768x16';
90
process.env.LIGHTHOUSE_CHROMIUM_PATH = 'chromium-browser';
86
- const child = spawn('xvfb start', [{ detached: true, stdio: ['ignore'] }]);
91
+ const child = spawn('xvfb start', [{detached: true, stdio: ['ignore']}]);
92
child.unref();
93
// wait for chrome to load then continue
94
await wait(3000);
@@ -128,4 +133,3 @@ async function runBenchmark(benchmark, headless) {
133
}
134
135
module.exports = runBenchmark;
131
-
scripts/bench/build.js
+22
-18
@@ -3,13 +3,9 @@
3
const Git = require('nodegit');
4
const rimraf = require('rimraf');
5
const ncp = require('ncp').ncp;
6
-const {
7
- existsSync,
8
-} = require('fs');
6
+const {existsSync} = require('fs');
7
const exec = require('child_process').exec;
10
-const {
11
- join,
12
-} = require('path');
8
+const {join} = require('path');
9
10
const reactUrl = 'https://github.com/facebook/react.git';
11
@@ -18,14 +14,16 @@ function cleanDir() {
14
}
15
16
function executeCommand(command) {
21
- return new Promise(_resolve => exec(command, (error) => {
22
- if (!error) {
23
- _resolve();
24
- } else {
25
- console.error(error);
26
- process.exit(1);
27
- }
28
- }));
17
+ return new Promise(_resolve =>
18
+ exec(command, error => {
19
+ if (!error) {
20
+ _resolve();
21
+ } else {
22
+ console.error(error);
23
+ process.exit(1);
24
+ }
25
+ })
26
+ );
27
}
28
29
function asyncCopyTo(from, to) {
@@ -51,9 +49,10 @@ async function buldAllBundles(reactPath = getDefaultReactPath()) {
49
50
async function buildBenchmark(reactPath = getDefaultReactPath(), benchmark) {
51
// get the build.js from the benchmark directory and execute it
54
- await require(
55
- join(__dirname, 'benchmarks', benchmark, 'build.js')
56
- )(reactPath, asyncCopyTo);
52
+ await require(join(__dirname, 'benchmarks', benchmark, 'build.js'))(
53
+ reactPath,
54
+ asyncCopyTo
55
+ );
56
}
57
58
function getBundleResults(reactPath = getDefaultReactPath()) {
@@ -69,7 +68,12 @@ async function getMergeBaseFromLocalGitRepo(localRepo) {
68
);
69
}
70
72
-async function buildBenchmarkBundlesFromGitRepo(commitId, skipBuild, url = reactUrl, clean) {
71
+async function buildBenchmarkBundlesFromGitRepo(
72
+ commitId,
73
+ skipBuild,
74
+ url = reactUrl,
75
+ clean
76
+) {
77
let repo;
78
const remoteRepoDir = getDefaultReactPath();
79
scripts/bench/runner.js
+23
-24
@@ -1,10 +1,7 @@
1
'use strict';
2
3
-const {
4
- readdirSync,
5
- statSync,
6
-} = require('fs');
7
-const { join } = require('path');
3
+const {readdirSync, statSync} = require('fs');
4
+const {join} = require('path');
5
const runBenchmark = require('./benchmark');
6
const {
7
buildAllBundles,
@@ -18,8 +15,8 @@ const printResults = require('./stats');
15
const serveBenchmark = require('./server');
16
17
function getBenchmarkNames() {
21
- return readdirSync(join(__dirname, 'benchmarks')).filter(
22
- file => statSync(join(__dirname, 'benchmarks', file)).isDirectory()
18
+ return readdirSync(join(__dirname, 'benchmarks')).filter(file =>
19
+ statSync(join(__dirname, 'benchmarks', file)).isDirectory()
20
);
21
}
22
@@ -43,13 +40,16 @@ async function runBenchmarks(reactPath) {
40
const benchmarkName = benchmarkNames[i];
41
42
if (
46
- !benchmarkFilter
47
- ||
43
+ !benchmarkFilter ||
44
(benchmarkFilter && benchmarkName.indexOf(benchmarkFilter) !== -1)
45
) {
50
- console.log(chalk.gray(`- Building benchmark "${chalk.white(benchmarkName)}"...`));
46
+ console.log(
47
+ chalk.gray(`- Building benchmark "${chalk.white(benchmarkName)}"...`)
48
+ );
49
await buildBenchmark(reactPath, benchmarkName);
52
- console.log(chalk.gray(`- Running benchmark "${chalk.white(benchmarkName)}"...`));
50
+ console.log(
51
+ chalk.gray(`- Running benchmark "${chalk.white(benchmarkName)}"...`)
52
+ );
53
results[benchmarkName] = await runBenchmark(benchmarkName, headless);
54
}
55
}
@@ -68,14 +68,13 @@ async function benchmarkRemoteMaster() {
68
69
if (!commit || typeof commit !== 'string') {
70
commit = await getMergeBaseFromLocalGitRepo(join(__dirname, '..', '..'));
71
- console.log(chalk.gray(`- Merge base commit ${chalk.white(commit.tostrS())}`));
71
+ console.log(
72
+ chalk.gray(`- Merge base commit ${chalk.white(commit.tostrS())}`)
73
+ );
74
}
75
return {
76
// we build the bundles from the React repo
75
- bundles: await buildBenchmarkBundlesFromGitRepo(
76
- commit,
77
- skipBuild
78
- ),
77
+ bundles: await buildBenchmarkBundlesFromGitRepo(commit, skipBuild),
78
// we use these bundles to run the benchmarks
79
benchmarks: await runBenchmarks(),
80
};
@@ -95,8 +94,8 @@ async function benchmarkLocal(reactPath) {
94
95
async function runLocalBenchmarks(showResults) {
96
console.log(
98
- chalk.white.bold('Running benchmarks for ')
99
- + chalk.green.bold('Local (Current Branch)')
97
+ chalk.white.bold('Running benchmarks for ') +
98
+ chalk.green.bold('Local (Current Branch)')
99
);
100
const localResults = await benchmarkLocal(join(__dirname, '..', '..'));
101
@@ -108,8 +107,8 @@ async function runLocalBenchmarks(showResults) {
107
108
async function runRemoteBenchmarks(showResults) {
109
console.log(
111
- chalk.white.bold('Running benchmarks for ')
112
- + chalk.yellow.bold('Remote (Merge Base)')
110
+ chalk.white.bold('Running benchmarks for ') +
111
+ chalk.yellow.bold('Remote (Merge Base)')
112
);
113
const remoteMasterResults = await benchmarkRemoteMaster();
114
@@ -121,10 +120,10 @@ async function runRemoteBenchmarks(showResults) {
120
121
async function compareLocalToMaster() {
122
console.log(
124
- chalk.white.bold('Comparing ')
125
- + chalk.green.bold('Local (Current Branch)')
126
- + chalk.white.bold(' to ')
127
- + chalk.yellow.bold('Remote (Merge Base)')
123
+ chalk.white.bold('Comparing ') +
124
+ chalk.green.bold('Local (Current Branch)') +
125
+ chalk.white.bold(' to ') +
126
+ chalk.yellow.bold('Remote (Merge Base)')
127
);
128
const localResults = await runLocalBenchmarks(false);
129
const remoteMasterResults = await runRemoteBenchmarks(false);
scripts/bench/server.js
+8
-7
@@ -2,12 +2,8 @@
2
3
const http2Server = require('http2');
4
const httpServer = require('http-server');
5
-const {
6
- existsSync,
7
- statSync,
8
- createReadStream,
9
-} = require('fs');
10
-const { join } = require('path');
5
+const {existsSync, statSync, createReadStream} = require('fs');
6
+const {join} = require('path');
7
const argv = require('minimist')(process.argv.slice(2));
8
const mime = require('mime');
9
@@ -21,7 +17,12 @@ function sendFile(filename, response) {
17
18
function createHTTP2Server(benchmark) {
19
const server = http2Server.createServer({}, (request, response) => {
24
- const filename = join(__dirname, 'benchmarks', benchmark, request.url).replace(/\?.*/g, '');
20
+ const filename = join(
21
+ __dirname,
22
+ 'benchmarks',
23
+ benchmark,
24
+ request.url
25
+ ).replace(/\?.*/g, '');
26
27
if (existsSync(filename) && statSync(filename).isFile()) {
28
sendFile(filename, response);
scripts/bench/stats.js
+24
-26
@@ -31,20 +31,19 @@ function calculateMeanAndSdOfRatioFromDeltaMethod(
31
semControl,
32
semTest
33
) {
34
- const mean = (
35
- ((meanTest - meanControl) / meanControl) -
36
- (Math.pow(semControl, 2) * meanTest / Math.pow(meanControl, 3))
37
- );
38
- const variance = (
34
+ const mean =
35
+ (meanTest - meanControl) / meanControl -
36
+ Math.pow(semControl, 2) * meanTest / Math.pow(meanControl, 3);
37
+ const variance =
38
Math.pow(semTest / meanControl, 2) +
40
- (Math.pow(semControl * meanTest, 2) / Math.pow(meanControl, 4))
41
- );
39
+ Math.pow(semControl * meanTest, 2) / Math.pow(meanControl, 4);
40
return [mean, Math.sqrt(variance)];
41
}
42
43
function addBenchmarkResults(table, localResults, remoteMasterResults) {
44
const benchmarks = Object.keys(
47
- (localResults && localResults.benchmarks) || (remoteMasterResults && remoteMasterResults.benchmarks)
45
+ (localResults && localResults.benchmarks) ||
46
+ (remoteMasterResults && remoteMasterResults.benchmarks)
47
);
48
benchmarks.forEach(benchmark => {
49
const rowHeader = [chalk.white.bold(benchmark)];
@@ -59,15 +58,12 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
58
}
59
table.push(rowHeader);
60
62
- const measurements = (
63
- (localResults && localResults.benchmarks[benchmark].averages)
64
- ||
65
- (remoteMasterResults && remoteMasterResults.benchmarks[benchmark].averages)
66
- );
61
+ const measurements =
62
+ (localResults && localResults.benchmarks[benchmark].averages) ||
63
+ (remoteMasterResults &&
64
+ remoteMasterResults.benchmarks[benchmark].averages);
65
measurements.forEach((measurement, i) => {
68
- const row = [
69
- chalk.gray(measurement.entry),
70
- ];
66
+ const row = [chalk.gray(measurement.entry)];
67
let remoteMean;
68
let remoteSem;
69
if (remoteMasterResults) {
@@ -75,7 +71,9 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
71
remoteSem = remoteMasterResults.benchmarks[benchmark].averages[i].sem;
72
// https://en.wikipedia.org/wiki/1.96 gives a 99% confidence interval.
73
const ci95 = remoteSem * 1.96;
78
- row.push(chalk.white(+remoteMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2)));
74
+ row.push(
75
+ chalk.white(+remoteMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2))
76
+ );
77
}
78
let localMean;
79
let localSem;
@@ -83,7 +81,9 @@ function addBenchmarkResults(table, localResults, remoteMasterResults) {
81
localMean = localResults.benchmarks[benchmark].averages[i].mean;
82
localSem = localResults.benchmarks[benchmark].averages[i].sem;
83
const ci95 = localSem * 1.96;
86
- row.push(chalk.white(+localMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2)));
84
+ row.push(
85
+ chalk.white(+localMean.toFixed(2) + ' ms +- ' + ci95.toFixed(2))
86
+ );
87
}
88
if (localResults && remoteMasterResults) {
89
row.push(percentChange(remoteMean, localMean, remoteSem, localSem));
@@ -107,17 +107,15 @@ function addBundleSizeComparions(table, localResults, remoteMasterResults) {
107
table.push(bundlesRowHeader);
108
109
const bundles = Object.keys(
110
- (localResults && localResults.bundles.bundleSizes)
111
- ||
112
- (remoteMasterResults && remoteMasterResults.bundles.bundleSizes)
110
+ (localResults && localResults.bundles.bundleSizes) ||
111
+ (remoteMasterResults && remoteMasterResults.bundles.bundleSizes)
112
);
113
bundles.forEach(bundle => {
115
- const row = [
116
- chalk.gray(bundle),
117
- ];
114
+ const row = [chalk.gray(bundle)];
115
let remoteSize = 0;
116
if (remoteMasterResults) {
120
- const remoteBundle = remoteSize = remoteMasterResults.bundles.bundleSizes[bundle];
117
+ const remoteBundle = (remoteSize =
118
+ remoteMasterResults.bundles.bundleSizes[bundle]);
119
120
if (remoteBundle) {
121
remoteSize = remoteSize.size;
@@ -152,7 +150,7 @@ function printResults(localResults, remoteMasterResults) {
150
if (localResults && remoteMasterResults) {
151
head.push('');
152
}
155
- const table = new Table({ head });
153
+ const table = new Table({head});
154
155
addBundleSizeComparions(table, localResults, remoteMasterResults);
156
addBenchmarkResults(table, localResults, remoteMasterResults);
scripts/prettier/index.js
+1
-1
@@ -39,7 +39,7 @@ const config = {
39
},
40
scripts: {
41
patterns: ['scripts/**/*.js'],
42
- ignore: ['**/bench/**'],
42
+ ignore: ['scripts/bench/benchmarks/**'],
43
options: {
44
'trailing-comma': 'es5',
45
},