UNPKG

assertthat

Version:
43 lines (42 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatResults = void 0; const common_tags_1 = require("common-tags"); const formatLine = function ({ scale, unit, time, deviation, regressionDeviation, scaleLength, unitLength, timeLength, precision }) { return (0, common_tags_1.oneLine) ` ${String(scale).padStart(scaleLength)}${(unit ? ` ${unit}` : '').padStart(unitLength + 1)}: ${String(time.toFixed(2)).padStart(timeLength + 3)}ms [+/-${(Math.abs(deviation) * 100).toFixed(precision)}%] [${regressionDeviation >= 0 ? '+' : ''}${(regressionDeviation * 100).toFixed(precision)}%] `; }; const formatResults = function ({ results, precision }) { const scaleLength = results.reduce((length, next) => { const nextLength = String(next.scale).length; return nextLength > length ? nextLength : length; }, 0); const unitLength = results.reduce((length, next) => { const nextLength = String(next.unit || '').length; return nextLength > length ? nextLength : length; }, 0); const timeLength = results.reduce((length, next) => { const nextLength = String(Math.floor(next.time)).length; return nextLength > length ? nextLength : length; }, 0); let formattedOutput = ''; for (const { scale, unit, time, deviation, regressionDeviation } of results) { formattedOutput += `${formatLine({ scale, unit, time, deviation, regressionDeviation, scaleLength, unitLength, timeLength, precision })}\n`; } return formattedOutput; }; exports.formatResults = formatResults;