Skip to content

Commit 52f6aaa

Browse files
committed
Add gas report docs
1 parent 905bae3 commit 52f6aaa

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

CHANGELOG.md

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

1212
### Forge
1313

14+
#### Added
15+
16+
- `--gas-report` flag to display a table of L2 gas breakdown for each contract and selector
17+
1418
#### Changed
1519

1620
- Gas values in fuzzing test output are now displayed as whole numbers without fractional parts

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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,38 @@ 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+
```shell
26+
$ snforge test --gas-report
27+
```
28+
29+
<details>
30+
<summary>Output:</summary>
31+
32+
```shell
33+
Collected 1 test(s) from hello_starknet package
34+
Running 1 test(s) from tests/
35+
[PASS] hello_starknet_integrationtest::test_contract::test_increase_balance (l1_gas: ~0, l1_data_gas: ~192, l2_gas: ~998280)
36+
╭------------------------+-------+-------+-------+---------+---------╮
37+
| HelloStarknet Contract | | | | | |
38+
+====================================================================+
39+
| Function Name | Min | Max | Avg | Std Dev | # Calls |
40+
|------------------------+-------+-------+-------+---------+---------|
41+
| get_balance | 13340 | 13340 | 13340 | 0 | 4 |
42+
|------------------------+-------+-------+-------+---------+---------|
43+
| increase_balance | 25540 | 61240 | 37440 | 16829 | 3 |
44+
╰------------------------+-------+-------+-------+---------+---------╯
45+
```
46+
47+
</details>
48+
<br>
49+
50+
Note that gas report data calculation ignores state changes, the cost of declared classes, Starknet OS overhead, L1 handler payload length and calldata payload length.
51+
2052
### Fuzzed Tests
2153

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

0 commit comments

Comments
 (0)