update the benchmark script (#13994)

This commit is contained in:
Keyan Zhang 2018-11-05 07:55:46 -08:00 committed by Dan Abramov
parent d34d1c3bae
commit ce90ffd045
4 changed files with 431 additions and 414 deletions

2
scripts/bench/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
react-dom.production.min.js
react.production.min.js

View File

@ -1,10 +1,10 @@
'use strict';
const Lighthouse = require('lighthouse');
const ChromeLauncher = require('lighthouse/lighthouse-cli/chrome-launcher.js')
.ChromeLauncher;
const chromeLauncher = require('chrome-launcher');
const stats = require('stats-analysis');
const config = require('lighthouse/lighthouse-core/config/perf.json');
const config = require('lighthouse/lighthouse-core/config/perf-config');
const spawn = require('child_process').spawn;
const os = require('os');
@ -14,27 +14,29 @@ function wait(val) {
return new Promise(resolve => setTimeout(resolve, val));
}
async function runScenario(benchmark, launcher) {
async function runScenario(benchmark, chrome) {
const port = chrome.port;
const results = await Lighthouse(
`http://localhost:8080/${benchmark}/`,
{
output: 'json',
disableCpuThrottling: false,
disableNetworkThrottling: false,
port,
},
config
);
const perfMarkings = results.audits['user-timings'].extendedInfo.value;
const perfMarkings = results.lhr.audits['user-timings'].details.items;
const entries = perfMarkings
.filter(marker => !marker.isMark)
.filter(({timingType}) => timingType !== 'Mark')
.map(({duration, name}) => ({
entry: name,
time: duration,
}));
entries.push({
entry: 'First Meaningful Paint',
time: results.audits['first-meaningful-paint'].rawValue,
time: results.lhr.audits['first-meaningful-paint'].rawValue,
});
return entries;
}
@ -97,16 +99,9 @@ async function initChrome() {
}
async function launchChrome(headless) {
let launcher;
try {
launcher = new ChromeLauncher({
additionalFlags: [headless ? '--headless' : ''],
});
await launcher.isDebuggerReady();
} catch (e) {
return launcher.run();
}
return launcher;
return await chromeLauncher.launch({
chromeFlags: [headless ? '--headless' : ''],
});
}
async function runBenchmark(benchmark, headless) {
@ -118,13 +113,13 @@ async function runBenchmark(benchmark, headless) {
await initChrome();
for (let i = 0; i < timesToRun; i++) {
let launcher = await launchChrome(headless);
let chrome = await launchChrome(headless);
results.runs.push(await runScenario(benchmark, launcher));
results.runs.push(await runScenario(benchmark, chrome));
// add a delay or sometimes it confuses lighthouse and it hangs
await wait(500);
try {
await launcher.kill();
await chrome.kill();
} catch (e) {}
}

View File

@ -7,10 +7,11 @@
},
"dependencies": {
"chalk": "^2.1.0",
"chrome-launcher": "^0.10.5",
"cli-table": "^0.3.1",
"http-server": "^0.10.0",
"http2": "^3.3.6",
"lighthouse": "2.0.0",
"lighthouse": "^3.2.1",
"mime": "^1.3.6",
"minimist": "^1.2.0",
"ncp": "^2.0.0",

File diff suppressed because it is too large Load Diff