Skip to content

Commit 00f6231

Browse files
authored
Merge 747ffa5 into 14c93db
2 parents 14c93db + 747ffa5 commit 00f6231

18 files changed

+60
-69
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@ Google PageSpeed Insights (PSI) score and metrics CLI
77

88
```
99
$ npx pagespeed-score --runs 3 https://www.google.com
10-
fetchTime score FCP FMP SI FCI TTI
11-
00:15:25 96 0.9 1.0 1.0 3.1 3.7
12-
00:15:31 95 0.9 1.0 1.1 3.4 3.9
13-
00:15:38 96 0.9 1.0 1.0 3.2 3.7
14-
15-
median 96 0.9 1.0 1.0 3.2 3.7
16-
stddev 0.6 0.0 0.0 0.1 0.2 0.1
17-
min 95 0.9 1.0 1.0 3.1 3.7
18-
max 96 0.9 1.0 1.1 3.4 3.9
10+
name score FCP FMP SI FCI TTI
11+
run 1 96 0.9 1.0 1.2 3.1 3.9
12+
run 2 96 0.9 1.0 1.0 3.1 3.7
13+
run 3 95 0.9 1.0 1.2 3.5 4.0
14+
15+
median 96 0.9 1.0 1.2 3.1 3.9
16+
stddev 0.6 0.0 0.0 0.1 0.2 0.2
17+
min 95 0.9 1.0 1.0 3.1 3.7
18+
max 96 0.9 1.0 1.2 3.5 4.0
1919
```
2020

21-
Note: most pages have much higher variability in their score.
22-
2321
## Metrics
2422

25-
* `fetchTime` is simply the time of the day (in UTC) when the run completed.
26-
2723
* `score` is the PageSpeed score based on [LightHouse perfomance scoring](https://github.com/GoogleChrome/lighthouse/blob/master/docs/scoring.md) calculated using FCP, FMP, SI, FCI and TTI.
2824

2925
* `FCP` is [First Contentful Paint](https://github.com/csabapalfi/awesome-web-performance-metrics#first-contentful-paint-fcp)
@@ -55,6 +51,8 @@ Output:
5551
[boolean] [default: false]
5652
--saveAssets, --output.saveAssets Save reports and traces
5753
[boolean] [default: false]
54+
--filePrefix, --output.filePrefix Saved asset file prefix
55+
[string] [default: ""]
5856
5957
Lighthouse:
6058
--local, --lighthouse.enabled Switch to local Lighthouse

lib/cli-options.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ const options = {
5858
default: false,
5959
alias: 'output.saveAssets',
6060
},
61+
filePrefix: {
62+
type: 'string',
63+
describe: 'Saved asset file prefix',
64+
group: 'Output:',
65+
default: '',
66+
alias: 'output.filePrefix',
67+
},
6168
local: {
6269
type: 'boolean',
6370
describe: 'Switch to local Lighthouse',

lib/counter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class Counter {
88
next() {
99
const run = ++this.run;
1010
return {
11-
value: {
11+
value: {
12+
index: run - this.warmupRuns,
1213
first: run === 1,
1314
warmup: run <= this.warmupRuns,
1415
last: run === this.maxRuns,

lib/fetcher.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ const {assetSaver} = require('./save-assets');
44
const {resultMapper} = require('./map-result');
55

66
class Fetcher {
7-
constructor(url, metrics, lighthouse, saveAssets) {
7+
constructor(url, metrics, lighthouse, output) {
88
this.mapResult = resultMapper(metrics);
99
this.getLighthouseResult = lighthouse.enabled ?
1010
runLighthouse.bind(null, lighthouse, url) :
1111
runPagespeed.bind(null, url);
12-
if (saveAssets) {
13-
this.saveAssets = assetSaver(lighthouse.modulePath);
12+
if (output.saveAssets) {
13+
this.saveAssets = assetSaver(lighthouse.modulePath, output.filePrefix);
1414
}
1515
}
1616

17-
async getResult() {
17+
async getResult(index) {
1818
const {result, artifacts} = await this.getLighthouseResult();
1919
if (this.saveAssets) {
20-
await this.saveAssets(result, artifacts);
20+
await this.saveAssets(index, result, artifacts);
2121
}
22-
return this.mapResult(result);
22+
return this.mapResult(index, result);
2323
}
2424
}
2525

lib/formatter.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
const {keys, entries} = Object;
22

3-
const identity = (x) => x;
43
const precision = (digits) => (n) => n.toFixed(digits);
54

65
const skip = ['type'];
76

87
const formats = {
9-
fetchTime: identity,
10-
name: s => s.padEnd(8),
8+
name: s => s.padEnd(6),
119
score: precision(0),
1210
score_stddev: precision(1),
1311
FCP: precision(1),
@@ -21,7 +19,10 @@ const formats = {
2119
};
2220

2321
function tableHeading(result) {
24-
return keys(result).filter(k => !skip.includes(k)).join('\t');
22+
return keys(result)
23+
.filter(k => !skip.includes(k))
24+
.map((k, index) => index === 0 ? k.padEnd(6) : k)
25+
.join('\t');
2526
}
2627

2728
function tsvFormatEntry(result) {

lib/get-stats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {median, sampleStandardDeviation, min, max} =
33

44
const {keys, entries} = Object;
55

6-
const noStats = ['type', 'fetchTime'];
6+
const noStats = ['type', 'name'];
77

88
const statistics = {
99
'median': median,

lib/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const {Runner} = require('./runner');
66
function main({
77
runs, warmupRuns,
88
url, metrics, lighthouse,
9-
output: {saveAssets, jsonl},
9+
output,
1010
}) {
1111
const counter = new Counter(runs, warmupRuns);
12-
const fetcher = new Fetcher(url, metrics, lighthouse, saveAssets);
13-
const formatter = new Formatter(jsonl);
12+
const fetcher = new Fetcher(url, metrics, lighthouse, output);
13+
const formatter = new Formatter(output.jsonl);
1414
return new Runner(counter, fetcher, formatter);
1515
}
1616

lib/map-result.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const {parse, format} = require('date-fns');
21
const {round} = Math;
32
const {entries} = Object;
43

@@ -14,10 +13,6 @@ const TTFB = {
1413
TTFB: 'time-to-first-byte',
1514
};
1615

17-
function formatTime(value) {
18-
return format(parse(value), 'HH:mm:ss');
19-
}
20-
2116
function formatScore(value) {
2217
return parseInt(round(value * 100), 10);
2318
}
@@ -65,9 +60,9 @@ function mapMarkValue(mark) {
6560
function resultMapper(metrics) {
6661
const {userTimingMarks, ttfb, benchmark} = metrics;
6762

68-
return ({fetchTime, categories, environment, audits}) => ({
63+
return (index, {categories, environment, audits}) => ({
6964
type: 'result',
70-
fetchTime: formatTime(fetchTime),
65+
name: `run ${index < 1 ? index - 1 : index}`,
7166
score: formatScore(categories.performance.score),
7267
...mapAudits(audits, DEFAULT_METRICS, mapMetricValue),
7368
...ttfb && mapAudits(audits, TTFB, mapTTFB),

lib/run-lighthouse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const getConfig = (modulePath) => ({
1111
'first-cpu-idle',
1212
'interactive',
1313
'time-to-first-byte',
14-
'user-timings'
14+
'user-timings',
1515
]
1616
}
1717
});

lib/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Runner {
1515
return Promise.resolve({done});
1616
}
1717

18-
const result = await fetcher.getResult();
18+
const result = await fetcher.getResult(run.index);
1919

2020
if (!run.warmup) {
2121
samples.push(result);

0 commit comments

Comments
 (0)