Created
September 2, 2024 15:29
-
-
Save drgorillamd/0bd3d8ede43bc854358b8223b649628c to your computer and use it in GitHub Desktop.
var instantiation once or in a loop?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.26; | |
import {Test, console} from "forge-std/Test.sol"; | |
// Ran 2 tests for test/Counter.t copy 2.sol:VarCreation | |
// [PASS] test_test1() (gas: 18480) | |
// [PASS] test_test2() (gas: 18320) | |
contract VarCreation is Test { | |
Test1 test1; | |
Test2 test2; | |
function setUp() public { | |
test1 = new Test1(); | |
test2 = new Test2(); | |
} | |
function test_test1() public { | |
test1.test(); | |
} | |
function test_test2() public { | |
test2.test(); | |
} | |
} | |
contract Test1 { | |
function test() external { | |
uint256 a; | |
uint256 b; | |
for (uint256 i = 0; i < 100; i++) { | |
a = i; | |
b = i + 1; | |
} | |
} | |
} | |
contract Test2 { | |
function test() external { | |
for (uint256 i = 0; i < 100; i++) { | |
uint256 a = i; | |
uint256 b = i + 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment