Skip to content

Commit da6c7a8

Browse files
committed
Format code size differences with grouping and unit display.
1 parent 7320214 commit da6c7a8

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

.github/workflows/check-binary-size.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,34 @@ jobs:
112112
return;
113113
}
114114
115+
const formatter = Intl.NumberFormat("en", {useGrouping: "always"});
116+
117+
const updated_str = formatter.format(updated);
118+
const reference_str = formatter.format(reference);
119+
115120
const diff = updated - reference;
116-
const plus = diff > 0 ? "+" : "";
117-
const diff_str = `${plus}${diff}B`;
121+
const diff_pct = (updated / reference) - 1;
122+
123+
const diff_str = Intl.NumberFormat("en", {
124+
useGrouping: "always",
125+
sign: "exceptZero"
126+
}).format(diff);
127+
128+
const diff_pct_str = Intl.NumberFormat("en", {
129+
style: "percent",
130+
useGrouping: "always",
131+
sign: "exceptZero",
132+
maximumFractionDigits: 2
133+
}).format(diff_pct);
118134
119135
if (diff !== 0) {
120-
const percent = (((updated / reference) - 1) * 100).toFixed(2);
121136
// The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines,
122137
// which is interpreted as a code block by Markdown.
123138
const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace.
124139
125-
Original binary size: **${reference}B**
126-
Updated binary size: **${updated}B**
127-
Difference: **${diff_str}** (${percent}%)`;
140+
Original binary size: **${reference_str} B**
141+
Updated binary size: **${updated_str} B**
142+
Difference: **${diff_str} B** (${diff_pct_str})`;
128143
129144
github.rest.issues.createComment({
130145
issue_number: context.issue.number,

0 commit comments

Comments
 (0)