Skip to content

Commit dd6ca0d

Browse files
committed
✨ Improve formatting
1 parent ef2545e commit dd6ca0d

File tree

7 files changed

+72
-55
lines changed

7 files changed

+72
-55
lines changed

β€ŽREADME.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- run: forge test --gas-report > gasreport.ansi
3535

3636
- name: Compare gas reports
37-
uses: Rubilmax/foundry-gas-report@v3.2
37+
uses: Rubilmax/foundry-gas-report@v3.3
3838
with:
3939
workflowId: foundry-gas-report.yml # must be the name of the workflow file
4040
ignore: test/**/* # optionally filter out gas reports from specific paths

β€Ždist/index.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ var TextAlign;
1919
TextAlign["CENTER"] = "center";
2020
})(TextAlign = exports.TextAlign || (exports.TextAlign = {}));
2121
const center = (text, length) => text.padStart((text.length + length) / 2).padEnd(length);
22-
const formatShellCell = (cell) => {
22+
const formatShellCell = (cell, length = 10) => {
2323
const format = colors_1.default[cell.delta > 0 ? "red" : cell.delta < 0 ? "green" : "reset"];
2424
return [
25-
format(cell.value.toLocaleString().padStart(10)),
26-
format((plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)),
25+
cell.value.toLocaleString().padStart(length) +
26+
" " +
27+
format(("(" + (plusSign(cell.delta) + cell.delta.toLocaleString()) + ")").padEnd(length)),
2728
colors_1.default.bold(format((plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8))),
2829
];
2930
};
@@ -34,11 +35,13 @@ const formatShellDiff = (diffs) => {
3435
const COLS = [
3536
{ txt: "", length: 0 },
3637
{ txt: "Contract", length: maxContractLength },
38+
{ txt: "Deployment Cost (+/-)", length: 32 },
3739
{ txt: "Method", length: maxMethodLength },
38-
{ txt: "Min", length: 34 },
39-
{ txt: "Avg", length: 34 },
40-
{ txt: "Median", length: 34 },
41-
{ txt: "Max", length: 34 },
40+
{ txt: "Min (+/-)", length: 32 },
41+
{ txt: "Avg (+/-)", length: 32 },
42+
{ txt: "Median (+/-)", length: 32 },
43+
{ txt: "Max (+/-)", length: 32 },
44+
{ txt: "# Calls (+/-)", length: 13 },
4245
{ txt: "", length: 0 },
4346
];
4447
const header = COLS.map((entry) => colors_1.default.bold(center(entry.txt, entry.length || 0)))
@@ -54,11 +57,13 @@ const formatShellDiff = (diffs) => {
5457
.map((method, methodIndex) => [
5558
"",
5659
colors_1.default.bold(colors_1.default.grey((methodIndex === 0 ? diff.name : "").padEnd(maxContractLength))),
60+
...(methodIndex === 0 ? (0, exports.formatShellCell)(diff.deploymentCost) : ["".padEnd(32)]),
5761
colors_1.default.italic(method.name.padEnd(maxMethodLength)),
5862
...(0, exports.formatShellCell)(method.min),
5963
...(0, exports.formatShellCell)(method.avg),
6064
...(0, exports.formatShellCell)(method.median),
6165
...(0, exports.formatShellCell)(method.max),
66+
(0, exports.formatShellCell)(method.calls, 6)[0],
6267
"",
6368
]
6469
.join(" | ")
@@ -86,6 +91,7 @@ const formatMarkdownSummaryCell = (rows) => [
8691
rows
8792
.map((row) => plusSign(row.delta) +
8893
row.delta.toLocaleString() +
94+
" " +
8995
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–"))
9096
.join("<br />"),
9197
rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
@@ -96,7 +102,6 @@ const formatMarkdownFullCell = (rows) => [
96102
"&nbsp;(" +
97103
plusSign(row.delta) +
98104
row.delta.toLocaleString() +
99-
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–") +
100105
")")
101106
.join("<br />"),
102107
rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
@@ -112,15 +117,17 @@ const MARKDOWN_SUMMARY_COLS = [
112117
const MARKDOWN_DIFF_COLS = [
113118
{ txt: "" },
114119
{ txt: "Contract", align: TextAlign.LEFT },
120+
{ txt: "Deployment Cost (+/-)", align: TextAlign.RIGHT },
115121
{ txt: "Method", align: TextAlign.LEFT },
116-
{ txt: "Min", align: TextAlign.RIGHT },
122+
{ txt: "Min (+/-)", align: TextAlign.RIGHT },
117123
{ txt: "%", align: TextAlign.RIGHT },
118-
{ txt: "Avg", align: TextAlign.RIGHT },
124+
{ txt: "Avg (+/-)", align: TextAlign.RIGHT },
119125
{ txt: "%", align: TextAlign.RIGHT },
120-
{ txt: "Median", align: TextAlign.RIGHT },
126+
{ txt: "Median (+/-)", align: TextAlign.RIGHT },
121127
{ txt: "%", align: TextAlign.RIGHT },
122-
{ txt: "Max", align: TextAlign.RIGHT },
128+
{ txt: "Max (+/-)", align: TextAlign.RIGHT },
123129
{ txt: "%", align: TextAlign.RIGHT },
130+
{ txt: "# Calls (+/-)", align: TextAlign.RIGHT },
124131
{ txt: "" },
125132
];
126133
const formatMarkdownDiff = (title, diffs) => {
@@ -164,11 +171,13 @@ const formatMarkdownDiff = (title, diffs) => {
164171
.flatMap((diff) => [
165172
"",
166173
`**${diff.name}**`,
174+
formatMarkdownFullCell([diff.deploymentCost])[0],
167175
diff.methods.map((method) => `_${method.name}_`).join("<br />"),
168176
...formatMarkdownFullCell(diff.methods.map((method) => method.min)),
169177
...formatMarkdownFullCell(diff.methods.map((method) => method.avg)),
170178
...formatMarkdownFullCell(diff.methods.map((method) => method.median)),
171179
...formatMarkdownFullCell(diff.methods.map((method) => method.max)),
180+
formatMarkdownFullCell(diff.methods.map((method) => method.calls))[0],
172181
"",
173182
]
174183
.join(" | ")
@@ -449,15 +458,18 @@ const computeDiffs = (sourceReports, compareReports) => {
449458
const srcReport = sourceReports[reportName];
450459
const cmpReport = compareReports[reportName];
451460
return Object.assign(Object.assign({}, srcReport), { deploymentCost: (0, exports.variation)(cmpReport.deploymentCost, srcReport.deploymentCost), deploymentSize: (0, exports.variation)(cmpReport.deploymentSize, srcReport.deploymentSize), methods: Object.values(srcReport.methods)
452-
.map((methodReport) => (Object.assign(Object.assign({}, methodReport), { min: (0, exports.variation)(cmpReport.methods[methodReport.name].min, srcReport.methods[methodReport.name].min), avg: (0, exports.variation)(cmpReport.methods[methodReport.name].avg, srcReport.methods[methodReport.name].avg), median: (0, exports.variation)(cmpReport.methods[methodReport.name].median, srcReport.methods[methodReport.name].median), max: (0, exports.variation)(cmpReport.methods[methodReport.name].max, srcReport.methods[methodReport.name].max), calls: (0, exports.variation)(cmpReport.methods[methodReport.name].max, srcReport.methods[methodReport.name].max) })))
461+
.map((methodReport) => (Object.assign(Object.assign({}, methodReport), { min: (0, exports.variation)(cmpReport.methods[methodReport.name].min, srcReport.methods[methodReport.name].min), avg: (0, exports.variation)(cmpReport.methods[methodReport.name].avg, srcReport.methods[methodReport.name].avg), median: (0, exports.variation)(cmpReport.methods[methodReport.name].median, srcReport.methods[methodReport.name].median), max: (0, exports.variation)(cmpReport.methods[methodReport.name].max, srcReport.methods[methodReport.name].max), calls: (0, exports.variation)(cmpReport.methods[methodReport.name].calls, srcReport.methods[methodReport.name].calls) })))
453462
.filter((row) => row.min.delta !== 0 ||
454463
row.avg.delta !== 0 ||
455464
row.median.delta !== 0 ||
456465
row.max.delta !== 0)
457-
.sort((method1, method2) => Math.max(Math.abs(method2.min.prcnt), Math.abs(method2.avg.prcnt), Math.abs(method2.median.prcnt), Math.abs(method2.max.prcnt)) -
458-
Math.max(Math.abs(method1.min.prcnt), Math.abs(method1.avg.prcnt), Math.abs(method1.median.prcnt), Math.abs(method1.max.prcnt))) });
466+
.sort((method1, method2) => Math.abs(method2.avg.prcnt) - Math.abs(method1.avg.prcnt)) });
459467
})
460-
.filter((diff) => diff.methods.length > 0);
468+
.filter((diff) => diff.methods.length > 0 ||
469+
diff.deploymentCost.delta !== 0 ||
470+
diff.deploymentSize.delta !== 0)
471+
.sort((diff1, diff2) => Math.max(...diff2.methods.map((method) => Math.abs(method.avg.prcnt))) -
472+
Math.max(...diff1.methods.map((method) => Math.abs(method.avg.prcnt))));
461473
};
462474
exports.computeDiffs = computeDiffs;
463475

β€Ždist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "foundry-gas-report",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "Github Action reporting gas diff from Foundry reports",
55
"author": "Romain Milon (Rubilmax) <[email protected]>",
66
"license": "UNLICENSED",

β€Žsrc/format.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ export enum TextAlign {
1111
const center = (text: string, length: number) =>
1212
text.padStart((text.length + length) / 2).padEnd(length);
1313

14-
export const formatShellCell = (cell: DiffCell) => {
14+
export const formatShellCell = (cell: DiffCell, length = 10) => {
1515
const format = colors[cell.delta > 0 ? "red" : cell.delta < 0 ? "green" : "reset"];
1616

1717
return [
18-
format(cell.value.toLocaleString().padStart(10)),
19-
format((plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)),
18+
cell.value.toLocaleString().padStart(length) +
19+
" " +
20+
format(("(" + (plusSign(cell.delta) + cell.delta.toLocaleString()) + ")").padEnd(length)),
2021
colors.bold(format((plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8))),
2122
];
2223
};
@@ -31,11 +32,13 @@ export const formatShellDiff = (diffs: DiffReport[]) => {
3132
const COLS = [
3233
{ txt: "", length: 0 },
3334
{ txt: "Contract", length: maxContractLength },
35+
{ txt: "Deployment Cost (+/-)", length: 32 },
3436
{ txt: "Method", length: maxMethodLength },
35-
{ txt: "Min", length: 34 },
36-
{ txt: "Avg", length: 34 },
37-
{ txt: "Median", length: 34 },
38-
{ txt: "Max", length: 34 },
37+
{ txt: "Min (+/-)", length: 32 },
38+
{ txt: "Avg (+/-)", length: 32 },
39+
{ txt: "Median (+/-)", length: 32 },
40+
{ txt: "Max (+/-)", length: 32 },
41+
{ txt: "# Calls (+/-)", length: 13 },
3942
{ txt: "", length: 0 },
4043
];
4144
const header = COLS.map((entry) => colors.bold(center(entry.txt, entry.length || 0)))
@@ -56,11 +59,13 @@ export const formatShellDiff = (diffs: DiffReport[]) => {
5659
colors.bold(
5760
colors.grey((methodIndex === 0 ? diff.name : "").padEnd(maxContractLength))
5861
),
62+
...(methodIndex === 0 ? formatShellCell(diff.deploymentCost) : ["".padEnd(32)]),
5963
colors.italic(method.name.padEnd(maxMethodLength)),
6064
...formatShellCell(method.min),
6165
...formatShellCell(method.avg),
6266
...formatShellCell(method.median),
6367
...formatShellCell(method.max),
68+
formatShellCell(method.calls, 6)[0],
6469
"",
6570
]
6671
.join(" | ")
@@ -94,6 +99,7 @@ const formatMarkdownSummaryCell = (rows: DiffCell[]) => [
9499
(row) =>
95100
plusSign(row.delta) +
96101
row.delta.toLocaleString() +
102+
" " +
97103
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–")
98104
)
99105
.join("<br />"),
@@ -108,7 +114,6 @@ const formatMarkdownFullCell = (rows: DiffCell[]) => [
108114
"&nbsp;(" +
109115
plusSign(row.delta) +
110116
row.delta.toLocaleString() +
111-
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–") +
112117
")"
113118
)
114119
.join("<br />"),
@@ -127,15 +132,17 @@ const MARKDOWN_SUMMARY_COLS = [
127132
const MARKDOWN_DIFF_COLS = [
128133
{ txt: "" },
129134
{ txt: "Contract", align: TextAlign.LEFT },
135+
{ txt: "Deployment Cost (+/-)", align: TextAlign.RIGHT },
130136
{ txt: "Method", align: TextAlign.LEFT },
131-
{ txt: "Min", align: TextAlign.RIGHT },
137+
{ txt: "Min (+/-)", align: TextAlign.RIGHT },
132138
{ txt: "%", align: TextAlign.RIGHT },
133-
{ txt: "Avg", align: TextAlign.RIGHT },
139+
{ txt: "Avg (+/-)", align: TextAlign.RIGHT },
134140
{ txt: "%", align: TextAlign.RIGHT },
135-
{ txt: "Median", align: TextAlign.RIGHT },
141+
{ txt: "Median (+/-)", align: TextAlign.RIGHT },
136142
{ txt: "%", align: TextAlign.RIGHT },
137-
{ txt: "Max", align: TextAlign.RIGHT },
143+
{ txt: "Max (+/-)", align: TextAlign.RIGHT },
138144
{ txt: "%", align: TextAlign.RIGHT },
145+
{ txt: "# Calls (+/-)", align: TextAlign.RIGHT },
139146
{ txt: "" },
140147
];
141148

@@ -189,11 +196,13 @@ export const formatMarkdownDiff = (title: string, diffs: DiffReport[]) => {
189196
[
190197
"",
191198
`**${diff.name}**`,
199+
formatMarkdownFullCell([diff.deploymentCost])[0],
192200
diff.methods.map((method) => `_${method.name}_`).join("<br />"),
193201
...formatMarkdownFullCell(diff.methods.map((method) => method.min)),
194202
...formatMarkdownFullCell(diff.methods.map((method) => method.avg)),
195203
...formatMarkdownFullCell(diff.methods.map((method) => method.median)),
196204
...formatMarkdownFullCell(diff.methods.map((method) => method.max)),
205+
formatMarkdownFullCell(diff.methods.map((method) => method.calls))[0],
197206
"",
198207
]
199208
.join(" | ")

β€Žsrc/report.ts

+14-18
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ export const computeDiffs = (sourceReports: GasReport, compareReports: GasReport
169169
srcReport.methods[methodReport.name].max
170170
),
171171
calls: variation(
172-
cmpReport.methods[methodReport.name].max,
173-
srcReport.methods[methodReport.name].max
172+
cmpReport.methods[methodReport.name].calls,
173+
srcReport.methods[methodReport.name].calls
174174
),
175175
}))
176176
.filter(
@@ -180,22 +180,18 @@ export const computeDiffs = (sourceReports: GasReport, compareReports: GasReport
180180
row.median.delta !== 0 ||
181181
row.max.delta !== 0
182182
)
183-
.sort(
184-
(method1, method2) =>
185-
Math.max(
186-
Math.abs(method2.min.prcnt),
187-
Math.abs(method2.avg.prcnt),
188-
Math.abs(method2.median.prcnt),
189-
Math.abs(method2.max.prcnt)
190-
) -
191-
Math.max(
192-
Math.abs(method1.min.prcnt),
193-
Math.abs(method1.avg.prcnt),
194-
Math.abs(method1.median.prcnt),
195-
Math.abs(method1.max.prcnt)
196-
)
197-
),
183+
.sort((method1, method2) => Math.abs(method2.avg.prcnt) - Math.abs(method1.avg.prcnt)),
198184
};
199185
})
200-
.filter((diff) => diff.methods.length > 0);
186+
.filter(
187+
(diff) =>
188+
diff.methods.length > 0 ||
189+
diff.deploymentCost.delta !== 0 ||
190+
diff.deploymentSize.delta !== 0
191+
)
192+
.sort(
193+
(diff1, diff2) =>
194+
Math.max(...diff2.methods.map((method) => Math.abs(method.avg.prcnt))) -
195+
Math.max(...diff1.methods.map((method) => Math.abs(method.avg.prcnt)))
196+
);
201197
};

β€Žtests/mocks/output.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
| Contract | Method | Avg (+/-) | % |
66
|:-|:-|-:|-:|
7-
| **Morpho** | _supply_ | +809❌ | **+0.23%** |
8-
| **PositionsManager** | _supplyLogic_<br />_borrowLogic_ | +849❌<br />+702❌ | **+0.25%**<br />**+0.13%** |
7+
| **PositionsManager** | _supplyLogic_<br />_borrowLogic_ | +849 ❌<br />+702 ❌ | **+0.25%**<br />**+0.13%** |
8+
| **Morpho** | _supply_ | +809 ❌ | **+0.23%** |
99
---
1010

1111
## Full diff report
1212

13-
| Contract | Method | Min | % | Avg | % | Median | % | Max | % |
14-
|:-|:-|-:|-:|-:|-:|-:|-:|-:|-:|
15-
| **Morpho** | _supply_ | 3,997&nbsp;(0βž–) | **0.00%** | 371,586&nbsp;(+809❌) | **+0.23%** | 395,247&nbsp;(+995❌) | **+0.27%** | 2,125,764&nbsp;(+304❌) | **+0.01%** |
16-
| **PositionsManager** | _supplyLogic_<br />_borrowLogic_ | 737&nbsp;(0βž–)<br />148,437&nbsp;(0βž–) | **0.00%**<br />**0.00%** | 365,894&nbsp;(+849❌)<br />542,977&nbsp;(+702❌) | **+0.25%**<br />**+0.13%** | 383,960&nbsp;(+995❌)<br />438,816&nbsp;(0βž–) | **+0.27%**<br />**0.00%** | 2,121,294&nbsp;(+304❌)<br />1,090,968&nbsp;(0βž–) | **+0.01%**<br />**0.00%** |
13+
| Contract | Deployment Cost (+/-) | Method | Min (+/-) | % | Avg (+/-) | % | Median (+/-) | % | Max (+/-) | % | # Calls (+/-) |
14+
|:-|-:|:-|-:|-:|-:|-:|-:|-:|-:|-:|-:|
15+
| **PositionsManager** | 4,546,050&nbsp;(+14,617) | _supplyLogic_<br />_borrowLogic_ | 737&nbsp;(0)<br />148,437&nbsp;(0) | **0.00%**<br />**0.00%** | 365,894&nbsp;(+849)<br />542,977&nbsp;(+702) | **+0.25%**<br />**+0.13%** | 383,960&nbsp;(+995)<br />438,816&nbsp;(0) | **+0.27%**<br />**0.00%** | 2,121,294&nbsp;(+304)<br />1,090,968&nbsp;(0) | **+0.01%**<br />**0.00%** | 500&nbsp;(0)<br />292&nbsp;(0) |
16+
| **Morpho** | 3,150,242&nbsp;(0) | _supply_ | 3,997&nbsp;(0) | **0.00%** | 371,586&nbsp;(+809) | **+0.23%** | 395,247&nbsp;(+995) | **+0.27%** | 2,125,764&nbsp;(+304) | **+0.01%** | 502&nbsp;(0) |

0 commit comments

Comments
Β (0)