Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve formatting
  • Loading branch information
swissspidy committed May 7, 2024
commit b58fd12cc01ce4fc50214ab2d315ac8a3741bae1
23 changes: 22 additions & 1 deletion bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ function formatAsMarkdownTable( rows ) {
return result;
}

/**
* Nicely formats a given value.
*
* @param {string} metric Metric.
* @param {number} value
*/
function formatValue( metric, value ) {
if ( 'wpMemoryUsage' === metric ) {
return `${ ( value / Math.pow( 10, 6 ) ).toFixed( 2 ) } MB`;
}

if ( 'wpDbQueries' === metric ) {
return value.toString();
}

return `${ value } ms`;
}

/**
* Runs the performances tests on an array of branches and output the result.
*
Expand Down Expand Up @@ -495,7 +513,10 @@ async function runPerformanceTests( branches, options ) {
) ) {
for ( const [ metric, value ] of Object.entries( metrics ) ) {
invertedResult[ metric ] = invertedResult[ metric ] || {};
invertedResult[ metric ][ branch ] = `${ value } ms`;
invertedResult[ metric ][ branch ] = formatValue(
metric,
value
);
}
}

Expand Down