Created
September 3, 2018 05:44
-
-
Save juntao/77022bf5c27550d7175897db69f8a8a2 to your computer and use it in GitHub Desktop.
CVM Performance Test: Addition
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.23; | |
contract addloops { | |
function add(uint256 x) public pure returns(string) { | |
string memory sum; | |
sum=eni("add", x); | |
return sum; | |
} | |
} |
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
addloops.add(2000000) |
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
var addloopsABI = [{"constant":true,"inputs":[{"name":"x","type":"uint256"}],"name":"add","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"}]; | |
var addloopsBC = '0x608060405234801561001057600080fd5b506101f0806100206000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631003e2d214610046575b600080fd5b34801561005257600080fd5b50610071600480360381019080803590602001909291905050506100ec565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b1578082015181840152602081019050610096565b50505050905090810190601f1680156100de5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f0900000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528460206040519081016040525280604051819003602090039052907f6164640000000000000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a72305820287012d49379416e8186fadde599b1053ab8d564531088a2b09b02d9d3ba48ec0029'; | |
var addloopsContract = web3.cmt.contract(addloopsABI); | |
var addloops = addloopsContract.new( | |
{ | |
from: web3.cmt.accounts[0], | |
data: addloopsBC, | |
gas: '4700000' | |
}, function (e, contract){ | |
console.log(e, contract); | |
if (typeof contract.address !== 'undefined') { | |
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); | |
} | |
}) |
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
#include <eni.h> | |
#include <string> | |
class Addition : public eni::EniBase | |
{ | |
public: | |
Addition(const std::string& pArgStr) : eni::EniBase(pArgStr) { } | |
~Addition() { } | |
private: | |
bool parse(const json::Array& pArgs) override { | |
x = pArgs[0].toInteger(); | |
return true; | |
} | |
eni::Gas gas() const override { | |
return 10000; | |
} | |
bool run(json::Array& pRetVal) override { | |
eni::Int sum = 0; | |
for(eni::Int i=0;i<x;i++){ | |
sum = sum + i; | |
} | |
std::string s=boost::lexical_cast<std::string>(sum); | |
pRetVal.emplace_back(s); | |
return true; | |
} | |
private: | |
eni::Int x; | |
}; | |
ENI_C_INTERFACE(add, Addition) |
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
CPPFLAGS=-I/home/ubuntu/libeni/include | |
CXXFLAGS=-std=c++11 -fPIC | |
LDFLAGS=-L/home/ubuntu/libeni/lib | |
LDADD=-leni | |
all: | |
g++ ${CPPFLAGS} ${CXXFLAGS} ${LDFLAGS} -shared -oeni_addition.so eni_addition.cpp ${LDADD} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment