Skip to content

Commit

Permalink
feat(world-modules): add gas reports to ERC721Module
Browse files Browse the repository at this point in the history
  • Loading branch information
intldds committed Nov 2, 2023
1 parent d3edec2 commit 994887a
Showing 1 changed file with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import { TokenURI } from "./tables/TokenURI.sol";
import { ERC721Registry } from "./tables/ERC721Registry.sol";
import { ERC721Metadata, ERC721MetadataData } from "./tables/ERC721Metadata.sol";

contract ERC721Module is Module {
import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol";

contract ERC721Module is Module, GasReporter {
error ERC721Module_InvalidNamespace(bytes14 namespace);

address immutable registrationLibrary = address(new ERC721ModuleRegistrationLibrary());
Expand Down Expand Up @@ -82,6 +84,68 @@ contract ERC721Module is Module {
function installRoot(bytes memory) public pure {
revert Module_RootInstallNotSupported();
}

function testGas() public {
startGasReport("getStaticByteLength: uint8");
SchemaType.UINT8.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: uint32");
SchemaType.UINT32.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: uint256");
SchemaType.UINT256.getStaticByteLength();
endGasReport();

startGasReport("getStaticByteLength: int8");
SchemaType.INT8.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: int32");
SchemaType.INT32.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: int256");
SchemaType.INT256.getStaticByteLength();
endGasReport();

startGasReport("getStaticByteLength: bytes1");
SchemaType.BYTES1.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: bytes4");
SchemaType.BYTES4.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: bytes32");
SchemaType.BYTES32.getStaticByteLength();
endGasReport();

startGasReport("getStaticByteLength: bool");
SchemaType.BOOL.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: address");
SchemaType.ADDRESS.getStaticByteLength();
endGasReport();

startGasReport("getStaticByteLength: uint8[]");
SchemaType.UINT8_ARRAY.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: uint32[]");
SchemaType.UINT32_ARRAY.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: uint256[]");
SchemaType.UINT256_ARRAY.getStaticByteLength();
endGasReport();

startGasReport("getStaticByteLength: int256[]");
SchemaType.INT256_ARRAY.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: bytes32[]");
SchemaType.BYTES32_ARRAY.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: bytes");
SchemaType.BYTES.getStaticByteLength();
endGasReport();
startGasReport("getStaticByteLength: string");
SchemaType.STRING.getStaticByteLength();
endGasReport();
}
}

contract ERC721ModuleRegistrationLibrary {
Expand Down

0 comments on commit 994887a

Please sign in to comment.