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 100e172 commit 4a38203
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 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
17 changes: 9 additions & 8 deletions lighthouse-core/audits/time-to-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TTIMetric extends Audit {
// Get our expected latency for the time window
const latencies = TracingProcessor.getRiskToResponsiveness(
model, trace, startTime, endTime, percentiles);
const estLatency = latencies[0].time.toFixed(2);
const estLatency = latencies[0].time;
foundLatencies.push({
estLatency: estLatency,
startTime: startTime.toFixed(1)
Expand All @@ -126,7 +126,8 @@ class TTIMetric extends Audit {
// 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,
expectedLatencyAtTTI: parseFloat(currentLatency.toFixed(3)),
foundLatencies
};

return TTIMetric.generateAuditResult({
score,
rawValue: timeToInteractive,
rawValue: parseFloat(timeToInteractive.toFixed(1)),
displayValue: `${timeToInteractive}ms`,
optimalValue: this.meta.optimalValue,
debugString: speedline.debugString,
Expand Down
10 changes: 5 additions & 5 deletions lighthouse-core/test/audits/time-to-interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ describe('Performance: time-to-interactive audit', () => {
};

return Audit.audit(artifacts).then(output => {
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.rawValue, 1105.8, output.debugString);
assert.equal(output.extendedInfo.value.expectedLatencyAtTTI, 20.724);
assert.equal(output.extendedInfo.value.timings.fMP, 1099.5);
assert.equal(output.extendedInfo.value.timings.timeToInteractive, 1105.798);
assert.equal(output.extendedInfo.value.timings.visuallyReady, 1105.798);
});
});
});

0 comments on commit 4a38203

Please sign in to comment.