Created
June 22, 2022 17:09
-
-
Save Vectorized/4ca34c76ba7853c65a0e515fdcb480d0 to your computer and use it in GitHub Desktop.
Mapping Gas Tests
This file contains hidden or 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: MIT | |
pragma solidity ^0.8.11; | |
import "@openzeppelin/contracts/utils/structs/BitMaps.sol"; | |
contract MappingTester { | |
using BitMaps for BitMaps.BitMap; | |
mapping(uint256 => bool) public map; | |
mapping(address => bool) public addrMap; | |
BitMaps.BitMap private btmp; | |
constructor() {} | |
function getFromMapping() external returns (bool result) { | |
// gas: 23449 | |
result = map[block.timestamp]; | |
} | |
function getFromBitmap() external returns(bool result) { | |
// gas: 23532 | |
result = btmp.get(block.timestamp); | |
} | |
function getFromAddrMap() external returns(bool result) { | |
// gas: 23391 | |
result = addrMap[msg.sender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment