Skip to content

Commit

Permalink
if we reduce significant digits with toFixed, always return to number.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Dec 14, 2016
1 parent 99b573f commit 562aee4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class FirstMeaningfulPaint extends Audit {
},
timings: {
navStart: 0,
fCP: firstContentfulPaint,
fMP: firstMeaningfulPaint
fCP: parseFloat(firstContentfulPaint.toFixed(3)),
fMP: parseFloat(firstMeaningfulPaint.toFixed(3))
}
};

Expand All @@ -107,7 +107,7 @@ class FirstMeaningfulPaint extends Audit {
return {
duration: `${firstMeaningfulPaint.toFixed(1)}`,
score: Math.round(score),
rawValue: firstMeaningfulPaint.toFixed(1),
rawValue: parseFloat(firstMeaningfulPaint.toFixed(1)),
extendedInfo
};
}
Expand Down
15 changes: 8 additions & 7 deletions lighthouse-core/audits/time-to-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ class TTIMetric extends Audit {
const estLatency = latencies[0].time.toFixed(2);
foundLatencies.push({
estLatency: estLatency,
startTime: startTime.toFixed(1)
startTime: parseFloat(startTime.toFixed(1))
});

// Grab this latency and try the threshold again
currentLatency = estLatency;
}
const timeToInteractive = parseFloat(startTime.toFixed(1));
// The start of our window is our TTI
const timeToInteractive = startTime;

// Use the CDF of a log-normal distribution for scoring.
// < 1200ms: score≈100
Expand All @@ -143,22 +144,22 @@ class TTIMetric extends Audit {

const extendedInfo = {
timings: {
fMP: fmpTiming.toFixed(1),
visuallyReady: visuallyReadyTiming.toFixed(1),
mainThreadAvail: startTime.toFixed(1)
fMP: parseFloat(fmpTiming.toFixed(3)),
visuallyReady: parseFloat(visuallyReadyTiming.toFixed(3)),
timeToInteractive: parseFloat(startTime.toFixed(3))
},
timestamps: {
fMP: fMPtsInMS * 1000,
visuallyReady: (visuallyReadyTiming + navStartTsInMS) * 1000,
mainThreadAvail: (timeToInteractive + navStartTsInMS) * 1000
timeToInteractive: (timeToInteractive + navStartTsInMS) * 1000
},
expectedLatencyAtTTI: currentLatency,
foundLatencies
};

return TTIMetric.generateAuditResult({
score,
rawValue: timeToInteractive,
rawValue: parseFloat(timeToInteractive.toFixed(1)),
displayValue: `${timeToInteractive}ms`,
optimalValue: this.meta.optimalValue,
debugString: speedline.debugString,
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/time-to-interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('Performance: time-to-interactive audit', () => {
assert.equal(output.rawValue, '1105.8', output.debugString);
assert.equal(output.extendedInfo.value.expectedLatencyAtTTI, '20.72');
assert.equal(output.extendedInfo.value.timings.fMP, '1099.5');
assert.equal(output.extendedInfo.value.timings.mainThreadAvail, '1105.8');
assert.equal(output.extendedInfo.value.timings.visuallyReady, '1105.8');
assert.equal(output.extendedInfo.value.timings.timeToInteractive, 1105.798);
assert.equal(output.extendedInfo.value.timings.visuallyReady, 1105.798);
});
});
});

0 comments on commit 562aee4

Please sign in to comment.