{"id":19125755,"url":"https://github.com/zeroekkusu/optimizooors-lab","last_synced_at":"2025-10-29T04:12:16.358Z","repository":{"id":43069601,"uuid":"468891792","full_name":"ZeroEkkusu/optimizooors-lab","owner":"ZeroEkkusu","description":"Measure gas savings with different Solidity optimizations","archived":false,"fork":false,"pushed_at":"2022-04-17T11:59:24.000Z","size":46,"stargazers_count":54,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-05T20:15:15.630Z","etag":null,"topics":["library","optimization","solidity","template"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZeroEkkusu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-11T20:32:01.000Z","updated_at":"2023-10-23T13:45:40.000Z","dependencies_parsed_at":"2022-09-10T20:51:20.247Z","dependency_job_id":null,"html_url":"https://github.com/ZeroEkkusu/optimizooors-lab","commit_stats":null,"previous_names":[],"tags_count":5,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroEkkusu%2Foptimizooors-lab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroEkkusu%2Foptimizooors-lab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroEkkusu%2Foptimizooors-lab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroEkkusu%2Foptimizooors-lab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZeroEkkusu","download_url":"https://codeload.github.com/ZeroEkkusu/optimizooors-lab/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252569648,"owners_count":21769517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","optimization","solidity","template"],"created_at":"2024-11-09T05:36:34.874Z","updated_at":"2025-10-29T04:12:16.278Z","avatar_url":"https://github.com/ZeroEkkusu.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧪 Optimizooor's Lab\n\n**Welcome to the 🧪 Optimizooor's Lab!**\n\nOptimize code and run tests with our equipment for optimizooors:\n- **[`MyLab`](#template-usage)**: An environment for running controlled experiments\n- **[`GFlask`](#gflask-usage)**: An instrument for measuring gas savings with different optimizations\n\n## Findings\n\n```text\nRunning 1 test for MyLab.json:MyLab\n[PASS] test() (gas: 510664)\nLogs:\n  Increment with `i += 1`\n  \n  Use `++i` instead\n  SAVES (GAS): 3\n  \n  Try `i = i + 1`\n  No savings.\n  \n  Try `i++`\n  [!] More expensive (gas): -2\n```\n\n## Research\n\n### [**⛳ Re:Golf Course**](https://github.com/ZeroEkkusu/re-golf-course)\n\nA list of common Solidity optimization tips and myths.\n\n## Instructions\n\nDownload `foundryup`\n\n```bash\ncurl -L https://foundry.paradigm.xyz | bash\n```\n\nInstall Foundry\n\n```bash\nfoundryup\n```\n\nCreate a new project using our template\n\n```bash\nforge init --template ZeroEkkusu/optimizooors-lab my-lab\n```\n\n... or install as a dependency\n\n```bash\nforge install ZeroEkkusu/optimizooors-lab\n```\n\n### Template usage\n\nTo use [`MyLab`](src/biohazard/MyLab.sol), provide code samples in [`Samples.sol`](src/Samples.sol):\n\n```solidity\ncontract Sample0 is SharedSetup {\n    function measureGas() external {\n        uint i;\n        i++;\n    }\n}\n\ncontract Sample1 is SharedSetup {\n    function measureGas() external {\n        uint i;\n        ++i;\n    }\n}\n```\n\n**Note:** For more complex setups, use [`SharedSetup`](src/Samples.sol) to minimize boilerplate.\n\nRun `forge test` to compare all provided samples against `Sample0`:\n\n```console\n00x@ubuntu:~$ forge test\nSAVES (GAS): 5\n```\n\nIt is possible to customize the console output with [`Labels`](src/Samples.sol):\n\n```solidity\nabstract contract Labels {\n    string label0 = \"Increment with `i++`\";\n    string label1 = \"Use `++i` instead\";\n    string label2 = \"\";\n    string label3 = \"\";\n    string label4 = \"\";\n    string label5 = \"\";\n}\n```\n\nLet's run `forge test` again:\n\n```console\n00x@ubuntu:~$ forge test\nIncrement `i++`\n\nUse `++i` instead\nSAVES (GAS): 5\n```\n\n**Note:** Combine with other commands at your disposal for more power. You can run `forge test --gas-report` to print the absolute gas costs as well.\n\n\u003e `Samples.sol` files are easy to share with others!\n\u003e\n\u003e Try copy-pasting their contents to another system and they'll work out of the box. No setup required.\n\n### GFlask usage\n\nTo use [`GFlask`](src/biohazard/GFlask.sol) in your project, mark the function with unoptimized code as `unoptimized` and the ones with optimized code as `optimized`.\n\nIt is possible to customize the console output with labels. In the example below, we left them unlabeled (`\"\"`).\n\nThen, call all the functions inside one `test` function, first calling the `unoptimized` function:\n\n```solidity\nimport \"optimizooors-lab/biohazard/GFlask.sol\"\n\ncontract Increment is GFlask {\n    function iPlusPlus() public unoptimized(\"\") {\n        uint i;\n        i++;\n    }\n\n    function plusPlusI() public optimized(\"\") {\n        uint i;\n        ++i;\n    }\n\n    function testIncrement() {\n        iPlusPlus();\n        plusPlusI();\n    }\n}\n```\n\nAfter running `forge test`, you get the following output:\n\n```console\n00x@ubuntu:~$ forge test\nSAVES (GAS): 5\n```\n\n**Note:** Combine with other commands at your disposal for more power. You can run `forge test --gas-report` to print the absolute gas costs as well.\n\n\u003cbr\u003e\n\n**Thank you for visiting the 🧪 Optimizooor's Lab!**\n\nMeasuring gas savings can be tricky sometimes. It is useful to have basic knowledge of how the optimizer works, so you can isolate the code properly.\n\nVisit [**⛳ Re:Golf Course**](https://github.com/ZeroEkkusu/re-golf-course) to learn more about this, as well as common optimization tips and myths.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroekkusu%2Foptimizooors-lab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeroekkusu%2Foptimizooors-lab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroekkusu%2Foptimizooors-lab/lists"}