Skip to content

Instantly share code, notes, and snippets.

@ChiTimesChi
Created June 7, 2022 21:09
Show Gist options
  • Save ChiTimesChi/ea61e78f34215a4492428cc33a350f93 to your computer and use it in GitHub Desktop.
Save ChiTimesChi/ea61e78f34215a4492428cc33a350f93 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "forge-std/Test.sol";
contract QueueGuy {
struct Queue {
uint256 index;
mapping(uint256 => uint256) data;
}
Queue public queue;
function init() public {
// queue.index = 1;
}
function add(uint256 _what) public {
uint256 index = queue.index;
queue.data[index] = _what;
queue.index = index + 1;
}
}
contract GasTest is Test {
QueueGuy public guy;
function setUp() public {
guy = new QueueGuy();
guy.init();
}
function test_add() public {
guy.add(1337);
guy.add(13);
guy.add(37);
}
}
╭───────────────────┬─────────────────┬───────┬────────┬───────┬─────────╮
│ QueueGuy contract ┆ ┆ ┆ ┆ ┆ │
╞═══════════════════╪═════════════════╪═══════╪════════╪═══════╪═════════╡
│ Deployment Cost ┆ Deployment Size ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 57705 ┆ 320 ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ Function Name ┆ min ┆ avg ┆ median ┆ max ┆ # calls │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ add ┆ 22669 ┆ 29969 ┆ 22669 ┆ 44569 ┆ 3 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ init ┆ 142 ┆ 142 ┆ 142 ┆ 142 ┆ 1 │
╰───────────────────┴─────────────────┴───────┴────────┴───────┴─────────╯
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "forge-std/Test.sol";
contract QueueGuy {
struct Queue {
uint256 index;
mapping(uint256 => uint256) data;
}
Queue public queue;
function init() public {
queue.index = 1;
}
function add(uint256 _what) public {
uint256 index = queue.index;
queue.data[index] = _what;
queue.index = index + 1;
}
}
contract GasTest is Test {
QueueGuy public guy;
function setUp() public {
guy = new QueueGuy();
guy.init();
}
function test_add() public {
guy.add(1337);
guy.add(13);
guy.add(37);
}
}
╭───────────────────┬─────────────────┬───────┬────────┬───────┬─────────╮
│ QueueGuy contract ┆ ┆ ┆ ┆ ┆ │
╞═══════════════════╪═════════════════╪═══════╪════════╪═══════╪═════════╡
│ Deployment Cost ┆ Deployment Size ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 59511 ┆ 329 ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ Function Name ┆ min ┆ avg ┆ median ┆ max ┆ # calls │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ add ┆ 22669 ┆ 24269 ┆ 22669 ┆ 27469 ┆ 3 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ init ┆ 22260 ┆ 22260 ┆ 22260 ┆ 22260 ┆ 1 │
╰───────────────────┴─────────────────┴───────┴────────┴───────┴─────────╯
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment