Skip to content

Instantly share code, notes, and snippets.

@Vectorized
Created June 22, 2022 17:09
Show Gist options
  • Save Vectorized/4ca34c76ba7853c65a0e515fdcb480d0 to your computer and use it in GitHub Desktop.
Save Vectorized/4ca34c76ba7853c65a0e515fdcb480d0 to your computer and use it in GitHub Desktop.
Mapping Gas Tests
// 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