Skip to content

Commit 17fbabb

Browse files
committed
Format code size differences with grouping and unit display.
1 parent 54e4ec8 commit 17fbabb

File tree

1 file changed

+21
-6
lines changed
  • .github/actions/report-code-size-changes

1 file changed

+21
-6
lines changed

.github/actions/report-code-size-changes/action.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,34 @@ runs:
3333
return;
3434
}
3535
36+
const formatter = Intl.NumberFormat("en", {useGrouping: "always"});
37+
38+
const updated_str = formatter.format(updated);
39+
const reference_str = formatter.format(reference);
40+
3641
const diff = updated - reference;
37-
const plus = diff > 0 ? "+" : "";
38-
const diff_str = `${plus}${diff}B`;
42+
const diff_pct = (updated / reference) - 1;
43+
44+
const diff_str = Intl.NumberFormat("en", {
45+
useGrouping: "always",
46+
sign: "exceptZero"
47+
}).format(diff);
48+
49+
const diff_pct_str = Intl.NumberFormat("en", {
50+
style: "percent",
51+
useGrouping: "always",
52+
sign: "exceptZero",
53+
maximumFractionDigits: 2
54+
}).format(diff_pct);
3955
4056
if (diff !== 0) {
41-
const percent = (((updated / reference) - 1) * 100).toFixed(2);
4257
// The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines,
4358
// which is interpreted as a code block by Markdown.
4459
const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace.
4560
46-
Original binary size: **${reference}B**
47-
Updated binary size: **${updated}B**
48-
Difference: **${diff_str}** (${percent}%)`;
61+
Original binary size: **${reference_str} B**
62+
Updated binary size: **${updated_str} B**
63+
Difference: **${diff_str} B** (${diff_pct_str})`;
4964
5065
github.rest.issues.createComment({
5166
issue_number: context.issue.number,

0 commit comments

Comments
 (0)