Skip to content

Instantly share code, notes, and snippets.

@gakonst
Created March 23, 2018 14:44
Show Gist options
  • Save gakonst/b9269d8f1691d213d549e99192ccc042 to your computer and use it in GitHub Desktop.
Save gakonst/b9269d8f1691d213d549e99192ccc042 to your computer and use it in GitHub Desktop.
Gas Testing for Libraries Public vs Internal
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