-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(metrics): switch to speedIndex from perceptualSpeedIndex (#4980)
- Loading branch information
1 parent
9b7b690
commit cc56516
Showing
20 changed files
with
315 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* @license Copyright 2016 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const Audit = require('./audit'); | ||
const Util = require('../report/v2/renderer/util'); | ||
|
||
class SpeedIndex extends Audit { | ||
/** | ||
* @return {!AuditMeta} | ||
*/ | ||
static get meta() { | ||
return { | ||
name: 'speed-index', | ||
description: 'Speed Index', | ||
helpText: 'Speed Index shows how quickly the contents of a page are visibly populated. ' + | ||
'[Learn more](https://developers.google.com/web/tools/lighthouse/audits/speed-index).', | ||
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC, | ||
requiredArtifacts: ['traces', 'devtoolsLogs'], | ||
}; | ||
} | ||
|
||
/** | ||
* @return {LH.Audit.ScoreOptions} | ||
*/ | ||
static get defaultOptions() { | ||
return { | ||
// see https://www.desmos.com/calculator/mdgjzchijg | ||
scorePODR: 1250, | ||
scoreMedian: 5500, | ||
}; | ||
} | ||
|
||
/** | ||
* Audits the page to give a score for the Speed Index. | ||
* @see https://github.com/GoogleChrome/lighthouse/issues/197 | ||
* @param {Artifacts} artifacts The artifacts from the gather phase. | ||
* @param {LH.Audit.Context} context | ||
* @return {Promise<AuditResult>} | ||
*/ | ||
static async audit(artifacts, context) { | ||
const trace = artifacts.traces[Audit.DEFAULT_PASS]; | ||
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS]; | ||
const metricComputationData = {trace, devtoolsLog, settings: context.settings}; | ||
const metricResult = await artifacts.requestSpeedIndex(metricComputationData); | ||
|
||
return { | ||
score: Audit.computeLogNormalScore( | ||
metricResult.timing, | ||
context.options.scorePODR, | ||
context.options.scoreMedian | ||
), | ||
rawValue: metricResult.timing, | ||
displayValue: Util.formatMilliseconds(metricResult.timing), | ||
}; | ||
} | ||
} | ||
|
||
module.exports = SpeedIndex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const MetricArtifact = require('./metric'); | ||
|
||
class SpeedIndex extends MetricArtifact { | ||
get name() { | ||
return 'SpeedIndex'; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.MetricComputationData} data | ||
* @param {Object} artifacts | ||
* @return {Promise<LH.Artifacts.Metric>} | ||
*/ | ||
async computeObservedMetric(data, artifacts) { | ||
const speedline = await artifacts.requestSpeedline(data.trace); | ||
const timing = Math.round(speedline.speedIndex); | ||
const timestamp = (timing + speedline.beginning) * 1000; | ||
return Promise.resolve({timing, timestamp}); | ||
} | ||
} | ||
|
||
module.exports = SpeedIndex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.