Skip to content

Commit

Permalink
update the benchmark script (#13994)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyz authored and gaearon committed Nov 5, 2018
1 parent d34d1c3 commit ce90ffd
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 416 deletions.
2 changes: 2 additions & 0 deletions scripts/bench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
react-dom.production.min.js
react.production.min.js
39 changes: 17 additions & 22 deletions scripts/bench/benchmark.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {}
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit ce90ffd

Please sign in to comment.