From 308fd627e5ca042bf37b8ae9e689a9846c77fc89 Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Wed, 29 Nov 2023 07:30:12 +0100 Subject: [PATCH] Include browser benchmark in the baseline data (#4015) --- lib/plugins/compare/helper.js | 46 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/plugins/compare/helper.js b/lib/plugins/compare/helper.js index 0c1f4c1dc3..c5757123e5 100644 --- a/lib/plugins/compare/helper.js +++ b/lib/plugins/compare/helper.js @@ -71,6 +71,24 @@ function getExtras(data) { return results; } +function getBrowserMetrics(data) { + const browserMetrics = { + cpuBenchmark: [] + }; + for (const run of data.browserScripts) { + browserMetrics['cpuBenchmark'].push(run.browser.cpuBenchmark); + } + + const results = {}; + for (const [metricName, values] of Object.entries(browserMetrics)) { + if (!results.browser) { + results.browser = {}; + } + results.browser[metricName] = new Metric(`${metricName}`, values); + } + return results; +} + function getTimings(data) { const timingMetrics = { ttfb: [], @@ -324,24 +342,16 @@ function getRenderBlocking(data) { } export function getMetrics(data) { - const userTimings = getUserTimings(data); - const elementTimings = getElementTimings(data); - const visualMetrics = getVisualMetrics(data); - const rb = getRenderBlocking(data); - const gWV = getGoogleWebVitals(data); - const cdp = getCDPPerformance(data); - const cpu = getCPU(data); - const timings = getTimings(data); - const extras = getExtras(data); return { - ...extras, - ...timings, - ...cpu, - ...cdp, - ...visualMetrics, - ...gWV, - ...rb, - ...elementTimings, - ...userTimings + ...getExtras(data), + ...getTimings(data), + ...getVisualMetrics(data), + ...getGoogleWebVitals(data), + ...getRenderBlocking(data), + ...getElementTimings(data), + ...getUserTimings(data), + ...getCPU(data), + ...getBrowserMetrics(data), + ...getCDPPerformance(data) }; }