Skip to content

Instantly share code, notes, and snippets.

@ernestognw
Last active June 20, 2023 03:58
Show Gist options
  • Save ernestognw/6bb125e99a80297616b1ecc26deae1fe to your computer and use it in GitHub Desktop.
Save ernestognw/6bb125e99a80297616b1ecc26deae1fe to your computer and use it in GitHub Desktop.
## Optimizer ON with 200 runs
| src/ProposalDeadline.sol:ProposalDeadline contract | | | | | |
|----------------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | |
| 185226 | 957 | | | | |
| Function Name | min | avg | median | max | # calls |
| add | 23322 | 23322 | 23322 | 23322 | 3 |
| getMemory | 2768 | 2768 | 2768 | 2768 | 1 |
| getRaw | 2639 | 2639 | 2639 | 2639 | 1 |
| getStorage | 2790 | 2790 | 2790 | 2790 | 1 |
## Optimizer ON with 200 runs and via-ir
| src/ProposalDeadline.sol:ProposalDeadline contract | | | | | |
|----------------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | |
| 139390 | 724 | | | | |
| Function Name | min | avg | median | max | # calls |
| add | 22920 | 22920 | 22920 | 22920 | 3 |
| getMemory | 2657 | 2657 | 2657 | 2657 | 1 |
| getRaw | 2500 | 2500 | 2500 | 2500 | 1 |
| getStorage | 2679 | 2679 | 2679 | 2679 | 1 |
## Optimizer ON with 200 runs
ProposalDeadlineTest:testGetMemory() (gas: 10032)
ProposalDeadlineTest:testGetRaw() (gas: 9948)
ProposalDeadlineTest:testGetStorage() (gas: 10055)
## Optimizer ON with 200 runs and via-ir
ProposalDeadlineTest:testGetMemory() (gas: 10062)
ProposalDeadlineTest:testGetRaw() (gas: 9773)
ProposalDeadlineTest:testGetStorage() (gas: 9909)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract ProposalDeadline {
struct ProposalCore {
address proposer;
uint48 voteStart;
uint32 voteDuration;
bool executed;
bool canceled;
}
mapping(uint256 => ProposalCore) private _proposals;
function add(uint256 proposalId, ProposalCore memory proposal) external {
_proposals[proposalId] = proposal;
}
function getMemory(uint256 proposalId) external view returns (uint256) {
ProposalCore memory proposal = _proposals[proposalId];
return proposal.voteStart + proposal.voteDuration;
}
function getStorage(uint256 proposalId) external view returns (uint256) {
ProposalCore memory proposal = _proposals[proposalId];
return proposal.voteStart + proposal.voteDuration;
}
function getRaw(uint256 proposalId) external view returns (uint256) {
return
_proposals[proposalId].voteStart +
_proposals[proposalId].voteDuration;
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import {ProposalDeadline} from "~/ProposalDeadline.sol";
contract ProposalDeadlineTest is Test {
ProposalDeadline public proposalDeadline;
uint256 public proposalId = 1;
function setUp() public {
proposalDeadline = new ProposalDeadline();
proposalDeadline.add(
proposalId,
ProposalDeadline.ProposalCore({
proposer: address(1),
voteStart: 1,
voteDuration: 1,
executed: false,
canceled: false
})
);
}
function testGetMemory() public {
proposalDeadline.getMemory(proposalId);
}
function testGetStorage() public {
proposalDeadline.getStorage(proposalId);
}
function testGetRaw() public {
proposalDeadline.getRaw(proposalId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment