https://github.com/guidanoli/gas-report-parser
Gas Reporter Parser
https://github.com/guidanoli/gas-report-parser
ethereum forge hardhat lpeg lua parser
Last synced: 7 months ago
JSON representation
Gas Reporter Parser
- Host: GitHub
- URL: https://github.com/guidanoli/gas-report-parser
- Owner: guidanoli
- License: gpl-3.0
- Created: 2023-02-03T17:55:08.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-23T01:44:49.000Z (about 2 years ago)
- Last Synced: 2025-01-17T13:30:11.226Z (9 months ago)
- Topics: ethereum, forge, hardhat, lpeg, lua, parser
- Language: Lua
- Homepage:
- Size: 68.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gas Report Parser
Parses gas reports in different formats and outputs a Lua table in the same format. These Lua tables can be later used to produce diffs and other analysis.
## Dependencies
* [Lua](https://www.lua.org) 5.4
* [LPEG](https://www.inf.puc-rio.br/~roberto/lpeg/) 1.0.2## Usage
### Parsing gas reports
On the repository root, run the following command, where `` is either `forge` or `hardhat`.
If this option is not provided, the tool tries to guess the format by running each parser.```sh
lua main.lua parse []
```The program reads the gas report from the standard input and prints the Lua table to the standard output.
You can redirect these streams to files through operating system pipes.### Comparing gas reports
You can compare two gas reports that have been already parsed into Lua tables with the following command. Here, we don't need to discriminate the source of the gas report, since they all use the same Lua table scheme. Because we need two inputs, we cannot use standard input anymore. Instead, we need to read such Lua tables from files `` and ``.
```sh
lua main.lua diff
```The output of this program is another Lua table which computes the absolute difference (`b - a`) and the relative difference (`(b - a) / a`) of every entry. If the absolute difference is zero, it is discarded. Also, if a table gets empty because all of its entries were discarded, the table itself also gets discarded. This is simply to minimize the size of the output and to make the end result more conscise. After all, we are only interested in what were the gas costs changes.
### Exporting diffs to Markdown tables
In the context of GitHub repositories, Markdown in the primary markup language. Because of this, we commonly format our tables using Markdown syntax. To make the process of exporting this information to Markdown simpler, you can run the following command.
```sh
lua main.lua printdiff
```Similar to `parse`, this program reads to `stdin` and writes to `stdout`.
## Handy shell script
If you want to compare two gas reports quickly, you can use the following script.
```sh
./quickdiff.sh
```## Tests
If you want to see the program in action, you can simply run the `runtests.sh` Shell script. The test inputs and outputs are stored in the `test/` folder. If, after running such script, none of the files were change, it is a good sign that your program is working as expected on your machine.