Skip to content

Commit 616e790

Browse files
authored
Add gas report docs (#3879)
Closes #3660
1 parent 8464eec commit 616e790

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Forge
11+
12+
#### Added
13+
14+
- `--gas-report` flag to display a table of L2 gas breakdown for each contract and selector
15+
1016
## [0.52.0] - 2025-11-05
1117

1218
### Forge

docs/src/appendix/snforge/test.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ Set tracked resource for test execution. Impacts overall test gas cost. Valid va
130130
- `cairo-steps`: track cairo steps, uses vm `ExecutionResources` (steps, builtins, memory holes) to describe resources consumed by the test.
131131
To learn more about fee calculation formula (and the impact of tracking sierra gas on it) please consult [starknet docs](https://docs.starknet.io/learn/protocol/fees#overall-fee)
132132

133+
## `--gas-report`
134+
Display a table of L2 gas breakdown for each contract and selector.
135+
133136
## `-P`, `--profile` `<PROFILE>`
134137
Specify the profile to use by name.
135138

docs/src/testing/gas-and-resource-estimation.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@ When the test passes with no errors, estimated gas is displayed this way:
1717
This gas calculation is based on the collected Sierra gas or VM resources (that you can [display additionally on demand](#usage)),
1818
storage updates, events and l1 <> l2 messages.
1919

20+
#### Gas Report
21+
22+
For individual tests, more detailed L2 gas usage can be displayed by passing the [`--gas-report`](../appendix/snforge/test.md#--gas-report) flag.
23+
This will generate a table that shows gas statistics for each contract and function.
24+
25+
<!-- { "ignored": true } -->
26+
```shell
27+
$ snforge test --gas-report
28+
```
29+
30+
<details>
31+
<summary>Output:</summary>
32+
33+
```shell
34+
Collected 1 test(s) from hello_starknet package
35+
Running 1 test(s) from tests/
36+
[PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (l1_gas: ~0, l1_data_gas: ~192, l2_gas: ~998280)
37+
╭------------------------+-------+-------+-------+---------+---------╮
38+
| HelloStarknet Contract | | | | | |
39+
+====================================================================+
40+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
41+
|------------------------+-------+-------+-------+---------+---------|
42+
| get_balance | 13340 | 13340 | 13340 | 0 | 4 |
43+
|------------------------+-------+-------+-------+---------+---------|
44+
| increase_balance | 25540 | 61240 | 37440 | 16829 | 3 |
45+
╰------------------------+-------+-------+-------+---------+---------╯
46+
```
47+
48+
</details>
49+
<br>
50+
51+
> 📝 **Note**
52+
>
53+
> Gas report data calculation ignores state changes, the cost of declared classes, Starknet OS overhead, L1 handler payload length and calldata payload length.
54+
2055
### Fuzzed Tests
2156

2257
While using the fuzzing feature additional gas statistics will be displayed:

0 commit comments

Comments
 (0)