/* SLOAD opcode which reads a data word from storage costs 200 gas. MSTORE and MLOAD opcodes which writes and reads a data word from memory costs 3 gas each. As such, it is much more efficient to declare to memory if used multiple times in function logic. */ uint256 public num = 50; function readStorage() public { if (num == 40 || num <= 10 && num > 100) { // execution cost: 885 gas } } function readMemory() public { uint256 mnum = num; if (mnum == 40 || mnum <= 10 && mnum > 100) { // execution cost: 605 gas } }
0.4.24