Created
March 23, 2018 14:44
-
-
Save gakonst/b9269d8f1691d213d549e99192ccc042 to your computer and use it in GitHub Desktop.
Gas Testing for Libraries Public vs Internal
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
pragma solidity ^0.4.21; | |
library TestLibPublic { | |
struct Data { | |
uint n; | |
} | |
function Set(Data storage self, uint a) public { | |
self.n = a; | |
} | |
function Get(Data storage self) view public returns(uint) { | |
return self.n; | |
} | |
} | |
library TestLibInternal { | |
struct Data { | |
uint n; | |
} | |
function Set(Data storage self, uint a) internal { | |
self.n = a; | |
} | |
function Get(Data storage self) view internal returns(uint) { | |
return self.n; | |
} | |
} | |
contract StorageOnePublic { | |
using TestLibPublic for TestLibPublic.Data; | |
TestLibPublic.Data data; | |
address public owner; | |
function StorageOne() public { | |
owner = msg.sender; | |
data.Set(5); | |
} | |
function GetData() external view returns(uint) { | |
return data.Get(); | |
} | |
} | |
contract StorageOneInternal { | |
using TestLibInternal for TestLibInternal.Data; | |
TestLibInternal.Data data; | |
address public owner; | |
function StorageOne() public { | |
owner = msg.sender; | |
data.Set(5); | |
} | |
function GetData() external view returns(uint) { | |
return data.Get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment