@@ -22,9 +22,9 @@ const center = (text, length) => text.padStart((text.length + length) / 2).padEn
2222const formatShellCell = (cell) => {
2323 const format = colors_1.default[cell.delta > 0 ? "red" : cell.delta < 0 ? "green" : "reset"];
2424 return [
25- format((isNaN( cell.value) ? "-" : cell.value. toLocaleString() ).padStart(10)),
26- format((isNaN(cell.delta) ? "-" : plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)),
27- colors_1.default.bold(format((isNaN(cell.prcnt) ? "-" : plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8))),
25+ format(cell.value. toLocaleString().padStart(10)),
26+ format((plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)),
27+ colors_1.default.bold(format((plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8))),
2828 ];
2929};
3030exports.formatShellCell = formatShellCell;
@@ -82,55 +82,93 @@ const alignPattern = (align = TextAlign.LEFT) => {
8282 return ":-:";
8383 }
8484};
85- const formatMarkdownCell = (rows) => [
86- rows.map((row) => (isNaN(row.value) ? "-" : row.value.toLocaleString())).join("<br />"),
85+ const formatMarkdownSummaryCell = (rows) => [
8786 rows
88- .map((row) => (isNaN(row.delta) ? "-" : plusSign(row.delta) + row.delta.toLocaleString()) +
87+ .map((row) => plusSign(row.delta) +
88+ row.delta.toLocaleString() +
8989 (row.delta > 0 ? "β" : row.delta < 0 ? "β
" : "β"))
9090 .join("<br />"),
91+ rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
92+ ];
93+ const formatMarkdownFullCell = (rows) => [
9194 rows
92- .map((row) => "**" + (isNaN(row.prcnt) ? "-" : plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%") + "**")
95+ .map((row) => row.value.toLocaleString() +
96+ " (" +
97+ plusSign(row.delta) +
98+ row.delta.toLocaleString() +
99+ (row.delta > 0 ? "β" : row.delta < 0 ? "β
" : "β") +
100+ ")")
93101 .join("<br />"),
102+ rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
103+ ];
104+ const MARKDOWN_SUMMARY_COLS = [
105+ { txt: "" },
106+ { txt: "Contract", align: TextAlign.LEFT },
107+ { txt: "Method", align: TextAlign.LEFT },
108+ { txt: "Avg (+/-)", align: TextAlign.RIGHT },
109+ { txt: "%", align: TextAlign.RIGHT },
110+ { txt: "" },
111+ ];
112+ const MARKDOWN_DIFF_COLS = [
113+ { txt: "" },
114+ { txt: "Contract", align: TextAlign.LEFT },
115+ { txt: "Method", align: TextAlign.LEFT },
116+ { txt: "Min", align: TextAlign.RIGHT },
117+ { txt: "%", align: TextAlign.RIGHT },
118+ { txt: "Avg", align: TextAlign.RIGHT },
119+ { txt: "%", align: TextAlign.RIGHT },
120+ { txt: "Median", align: TextAlign.RIGHT },
121+ { txt: "%", align: TextAlign.RIGHT },
122+ { txt: "Max", align: TextAlign.RIGHT },
123+ { txt: "%", align: TextAlign.RIGHT },
124+ { txt: "" },
94125];
95126const formatMarkdownDiff = (title, diffs) => {
96- const COLS = [
97- { txt: "" },
98- { txt: "Contract", align: TextAlign.LEFT },
99- { txt: "Method", align: TextAlign.LEFT },
100- { txt: "Min", align: TextAlign.RIGHT },
101- { txt: "(+/-)", align: TextAlign.RIGHT },
102- { txt: "%", align: TextAlign.RIGHT },
103- { txt: "Avg", align: TextAlign.RIGHT },
104- { txt: "(+/-)", align: TextAlign.RIGHT },
105- { txt: "%", align: TextAlign.RIGHT },
106- { txt: "Median", align: TextAlign.RIGHT },
107- { txt: "(+/-)", align: TextAlign.RIGHT },
108- { txt: "%", align: TextAlign.RIGHT },
109- { txt: "Max", align: TextAlign.RIGHT },
110- { txt: "(+/-)", align: TextAlign.RIGHT },
111- { txt: "%", align: TextAlign.RIGHT },
112- { txt: "" },
113- ];
114- const header = COLS.map((entry) => entry.txt)
127+ const summaryHeader = MARKDOWN_SUMMARY_COLS.map((entry) => entry.txt)
128+ .join(" | ")
129+ .trim();
130+ const summaryHeaderSeparator = MARKDOWN_SUMMARY_COLS.map((entry) => entry.txt ? alignPattern(entry.align) : "")
131+ .join("|")
132+ .trim();
133+ const diffHeader = MARKDOWN_DIFF_COLS.map((entry) => entry.txt)
115134 .join(" | ")
116135 .trim();
117- const contractSeparator = COLS .map((entry) => ( entry.txt ? alignPattern(entry.align) : "") )
136+ const diffHeaderSeparator = MARKDOWN_DIFF_COLS .map((entry) => entry.txt ? alignPattern(entry.align) : "")
118137 .join("|")
119138 .trim();
120139 return [
121140 "# " + title,
122141 "",
123- header,
124- contractSeparator,
142+ "## Summary",
143+ "",
144+ summaryHeader,
145+ summaryHeaderSeparator,
146+ diffs
147+ .flatMap((diff) => [
148+ "",
149+ `**${diff.name}**`,
150+ diff.methods.map((method) => `_${method.name}_`).join("<br />"),
151+ ...formatMarkdownSummaryCell(diff.methods.map((method) => method.avg)),
152+ "",
153+ ]
154+ .join(" | ")
155+ .trim())
156+ .join("\n"),
157+ "---",
158+ "",
159+ "## Full diff report",
160+ "",
161+ diffHeader,
162+ diffHeaderSeparator,
125163 diffs
126164 .flatMap((diff) => [
127165 "",
128166 `**${diff.name}**`,
129167 diff.methods.map((method) => `_${method.name}_`).join("<br />"),
130- ...formatMarkdownCell (diff.methods.map((method) => method.min)),
131- ...formatMarkdownCell (diff.methods.map((method) => method.avg)),
132- ...formatMarkdownCell (diff.methods.map((method) => method.median)),
133- ...formatMarkdownCell (diff.methods.map((method) => method.max)),
168+ ...formatMarkdownFullCell (diff.methods.map((method) => method.min)),
169+ ...formatMarkdownFullCell (diff.methods.map((method) => method.avg)),
170+ ...formatMarkdownFullCell (diff.methods.map((method) => method.median)),
171+ ...formatMarkdownFullCell (diff.methods.map((method) => method.max)),
134172 "",
135173 ]
136174 .join(" | ")
0 commit comments