Skip to content

Instantly share code, notes, and snippets.

@Hokid
Created November 26, 2018 21:37
Show Gist options
  • Save Hokid/ead56dd096e4180eb0f09bf6f53083ba to your computer and use it in GitHub Desktop.
Save Hokid/ead56dd096e4180eb0f09bf6f53083ba to your computer and use it in GitHub Desktop.
test1_solc
pragma solidity ^0.4.24;
contract TestA {
struct Test {
address _address;
}
struct Test2 {
address account;
address _address;
}
mapping(address => Test) _mapping;
Test2[] _list;
mapping(address => bool) _has;
mapping(address => uint) _indexes;
address[] _addresses;
function addv1() public {
_mapping[msg.sender]._address = msg.sender;
if (!_has[msg.sender]) {
_addresses.push(msg.sender);
_has[msg.sender] = true;
}
}
function removev1() public {
for(uint i = 0; i < _addresses.length; i++) {
_has[_addresses[i]] = false;
}
_addresses.length = 0;
}
function addv2() public {
for(uint i = 0; i < _list.length; i++) {
if(_list[i].account == msg.sender) {
_list[i]._address = msg.sender;
return;
}
}
_list.push(Test2({ account: msg.sender, _address: msg.sender }));
}
function removev2() public {
_list.length = 0;
}
function addv3() public {
_mapping[msg.sender]._address = msg.sender;
for(uint i = 0; i < _addresses.length; i++) {
if (_addresses[i] == msg.sender) return;
}
_addresses.push(msg.sender);
}
function removev3() public {
_addresses.length = 0;
}
function addv4() public {
if(_has[msg.sender]) {
_list[_indexes[msg.sender]]._address = msg.sender;
return;
}
_has[msg.sender] = true;
_indexes[msg.sender] = _list.length;
_list.push(Test2({ account: msg.sender, _address: msg.sender }));
}
function removev4() public {
for(uint i = 0; i < _list.length; i++) {
_has[_list[i].account] = false;
}
_list.length = 0;
}
}
1 records | gas
1 | 81828 + 17081 (103100 + 19177) | 98909 (122277)
2 | 61493 + 16149 (82765 + 18711) | 77642 (101476)
3 | 61417 + 10624 (82689 + 15948) | 72041 (98637)
4 | 87235 + 22689 (108507 + 21981) | 109924 (130488)
1 records (overwrite) | gas
1 | 66828 + 17081 (88100 + 19177) | 83909 (107277)
2 | 61493 + 16149 (82765 + 18711) | 77642 (101476)
3 | 46417 + 10624 (67689 + 15948) | 57041 (83637)
4 | 87235 + 22689 (108507 + 21981) | 109924 (130488)
3 records | gas
1 | 81828 + 66828 + 66828 + 39481 (103100 + 88100 + 88100 + 30377) | 254965 (309677)
2 | 61493 + 47333 + 48173 + 37237 (82765 + 68605 + 69445 + 29255) | 194236 (250070)
3 | 61417 + 47240 + 48063 + 20738 (82689 + 68512 + 69335 + 21005) | 177458 (241541)
4 | 87235 + 87235 + 87235 + 56097 (108507 + 108507 + 108507 + 38685) | 317802 (364206)
3 records (overwrite) | gas
1 | 66828 + 51828 + 51828 + 39481 (88100 + 73100 + 73100 + 30377) | 209965 (264677)
2 | 61493 + 47333 + 48173 + 37237 (82765 + 68605 + 69445 + 29255) | 194236 (250070)
3 | 46417 + 32240 + 33063 + 20738 (67689 + 53512 + 54335 + 21005) | 132458 (196541)
4 | 87235 + 72235 + 72235 + 56097 (108507 + 93507 + 93507 + 38685) | 287802 (334206)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment