Instantly share code, notes, and snippets.

Embed
What would you like to do?
EVM Performance Test
loops.echo(10)
loops.add(2000000)
loops.mul(1000000)
loops.sort(6000)
var loopsContract = web3.eth.contract([{"constant":true,"inputs":[{"name":"x","type":"uint256"}],"name":"add","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"x","type":"uint256"}],"name":"mul","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"x","type":"uint256"}],"name":"echo","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"x","type":"uint256"}],"name":"sort","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"}]);
var loops = loopsContract.new(
{
from: web3.eth.accounts[0],
data: '0x608060405234801561001057600080fd5b506105cb806100206000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631003e2d214610067578063131e2f18146100a85780636279e43c146100e9578063fe9138651461012a575b600080fd5b34801561007357600080fd5b506100926004803603810190808035906020019092919050505061016b565b6040518082815260200191505060405180910390f35b3480156100b457600080fd5b506100d36004803603810190808035906020019092919050505061019c565b6040518082815260200191505060405180910390f35b3480156100f557600080fd5b50610114600480360381019080803590602001909291905050506101f8565b6040518082815260200191505060405180910390f35b34801561013657600080fd5b5061015560048036038101908080359060200190929190505050610202565b6040518082815260200191505060405180910390f35b6000806000809150600090505b838110156101925780820191508080600101915050610178565b8192505050919050565b6000806000806000925060029150600090505b848110156101ed576001600a828115156101c557fe5b0601820291506103e88211156101e057600291506001830192505b80806001019150506101af565b829350505050919050565b6000819050919050565b60006060600080600080600080600a60405190808252806020026020018201604052801561023f5781602001602082028038833980820191505090505b509650600a87600081518110151561025357fe5b9060200190602002018181525050600987600181518110151561027257fe5b9060200190602002018181525050600887600281518110151561029157fe5b906020019060200201818152505060078760038151811015156102b057fe5b906020019060200201818152505060068760048151811015156102cf57fe5b906020019060200201818152505060058760058151811015156102ee57fe5b9060200190602002018181525050600487600681518110151561030d57fe5b9060200190602002018181525050600387600781518110151561032c57fe5b9060200190602002018181525050600287600881518110151561034b57fe5b9060200190602002018181525050600187600981518110151561036a57fe5b906020019060200201818152505060009550600094505b888510156105905760009350600092505b600187510383101561048357600091505b8260018851030382101561046a5786838151811015156103bf57fe5b9060200190602002015187838151811015156103d757fe5b90602001906020020151111561045d5786828151811015156103f557fe5b906020019060200201519050866001830181518110151561041257fe5b90602001906020020151878381518110151561042a57fe5b906020019060200201818152505080876001840181518110151561044a57fe5b9060200190602002018181525050600193505b81806001019250506103a3565b83151561047657610483565b8280600101935050610392565b60009350600092505b600187510383101561057d57600091505b826001885103038210156105645786838151811015156104b957fe5b9060200190602002015187838151811015156104d157fe5b9060200190602002015110156105575786828151811015156104ef57fe5b906020019060200201519050866001830181518110151561050c57fe5b90602001906020020151878381518110151561052457fe5b906020019060200201818152505080876001840181518110151561054457fe5b9060200190602002018181525050600193505b818060010192505061049d565b8315156105705761057d565b828060010193505061048c565b8651860195508480600101955050610381565b859750505050505050509190505600a165627a7a7230582071d1893b4ec70f882082be782b6caf18d7fc983fe7bdd0540d2ae3f2dc6c3ccb0029',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
pragma solidity ^0.4.24;
contract Loops {
function echo (uint256 x) public pure returns(uint256) {
return x;
}
function add(uint256 x) public pure returns(uint256) {
uint256 sum=0;
for(uint256 i=0;i<x;i++){
sum = sum + i;
}
return sum;
}
function mul(uint256 x) public pure returns(uint256) {
uint256 sum = 0;
uint256 prod = 2;
for(uint256 i=0;i<x;i++){
prod = prod * (i%10 + 1);
if (prod > 1000) {
prod = 2;
sum = sum + 1;
}
}
return sum;
}
function sort(uint256 x) public pure returns(uint256){
uint256[] memory arr = new uint256[](10);
arr[0] = 10;
arr[1] = 9;
arr[2] = 8;
arr[3] = 7;
arr[4] = 6;
arr[5] = 5;
arr[6] = 4;
arr[7] = 3;
arr[8] = 2;
arr[9] = 1;
uint256 sum = 0;
for(uint256 k=0;k<x;k++){
bool swapped=false;
for(uint256 i=0; i<arr.length-1; i++){
for(uint256 j=0; j<arr.length-1-i; j++){
if(arr[j]>arr[i]){
uint256 temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
swapped=true;
}
}
if(!swapped) break;
}
swapped=false;
for(i=0; i<arr.length-1; i++){
for(j=0; j<arr.length-1-i; j++){
if(arr[j]<arr[i]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
swapped=true;
}
}
if(!swapped) break;
}
sum = sum + arr.length;
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment