Skip to content

Instantly share code, notes, and snippets.

@0xbepresent
Created August 13, 2022 01:06
Show Gist options
  • Save 0xbepresent/3b009070d671349351a4301a494d3d8f to your computer and use it in GitHub Desktop.
Save 0xbepresent/3b009070d671349351a4301a494d3d8f to your computer and use it in GitHub Desktop.
// Usign the gas-lab as a reference https://github.com/0xKitsune/gas-lab
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.12;
import "../../lib/test.sol";
import "../../lib/Console.sol";
contract GasTest is DSTest {
Contract0 c0;
Contract1 c1;
function setUp() public {
c0 = new Contract0();
c1 = new Contract1();
}
function testGas() public view{
c0.withArrayLengthInside();
c1.withArrayLengthOutside();
}
}
contract Contract0 {
uint[] myarray = [1, 2, 3];
function withArrayLengthInside() public view {
uint256 j = 0;
for (uint256 i; i < myarray.length; ++i) {
j++;
}
}
}
contract Contract1 {
uint[] myarray = [1, 2, 3];
function withArrayLengthOutside() public view {
uint256 j = 0;
uint256 len = myarray.length;
for (uint256 i; i < len; ++i) {
j++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment