Skip to content

Instantly share code, notes, and snippets.

@coburncoburn
Created January 12, 2019 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coburncoburn/48d0caeecc2b877b56900629428669e8 to your computer and use it in GitHub Desktop.
Save coburncoburn/48d0caeecc2b877b56900629428669e8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.2+commit.1df8f40c.js&optimize=false&gist=
pragma solidity ^0.5.2;
contract AssetsListTest {
uint8[] arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29];
uint8[] nearlyFull = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28];
uint8[] empty;
constructor() public {
}
function findCachedStorageLoadWorst() public returns (bool) {
bool found;
uint8[] memory arrx = arr;
uint l = arrx.length;
for(uint i = 0; i < l; i++) {
if(arrx[i] == 99) {
found = true;
break;
}
}
return found;
}
function findCachedStorageLoadBest() public returns (bool) {
bool found;
uint8[] memory arrx = arr;
uint l = arrx.length;
for(uint i = 0; i < l; i++) {
if(arrx[i] == 0) {
found = true;
break;
}
}
return found;
}
function findUnCachedStorageLoadBest() public returns (bool) {
bool found;
uint l = arr.length;
for(uint i = 0; i < l; i++) {
if(arr[i] == 0) {
found = true;
break;
}
}
return found;
}
function findUnCachedStorageLoadWorst() public returns (bool) {
bool found;
uint l = arr.length;
for(uint i = 0; i < l; i++) {
if(arr[i] == 99) {
found = true;
break;
}
}
return found;
}
function pushLastElement() public {
nearlyFull.push(40);
}
function pushFirstElement() public {
empty.push(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment