|
|
@ -17,9 +17,11 @@ |
|
|
|
package runtime |
|
|
|
package runtime |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"encoding/binary" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"math/big" |
|
|
|
"math/big" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
|
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
@ -241,6 +243,41 @@ func BenchmarkEVM_SWAP1(b *testing.B) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkEVM_RETURN(b *testing.B) { |
|
|
|
|
|
|
|
// returns a contract that returns a zero-byte slice of len size
|
|
|
|
|
|
|
|
returnContract := func(size uint64) []byte { |
|
|
|
|
|
|
|
contract := []byte{ |
|
|
|
|
|
|
|
byte(vm.PUSH8), 0, 0, 0, 0, 0, 0, 0, 0, // PUSH8 0xXXXXXXXXXXXXXXXX
|
|
|
|
|
|
|
|
byte(vm.PUSH0), // PUSH0
|
|
|
|
|
|
|
|
byte(vm.RETURN), // RETURN
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
binary.BigEndian.PutUint64(contract[1:], size) |
|
|
|
|
|
|
|
return contract |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil) |
|
|
|
|
|
|
|
contractAddr := common.BytesToAddress([]byte("contract")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, n := range []uint64{1_000, 10_000, 100_000, 1_000_000} { |
|
|
|
|
|
|
|
b.Run(strconv.FormatUint(n, 10), func(b *testing.B) { |
|
|
|
|
|
|
|
b.ReportAllocs() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contractCode := returnContract(n) |
|
|
|
|
|
|
|
state.SetCode(contractAddr, contractCode) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ { |
|
|
|
|
|
|
|
ret, _, err := Call(contractAddr, []byte{}, &Config{State: state}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
b.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if uint64(len(ret)) != n { |
|
|
|
|
|
|
|
b.Fatalf("expected return size %d, got %d", n, len(ret)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func fakeHeader(n uint64, parentHash common.Hash) *types.Header { |
|
|
|
func fakeHeader(n uint64, parentHash common.Hash) *types.Header { |
|
|
|
header := types.Header{ |
|
|
|
header := types.Header{ |
|
|
|
Coinbase: common.HexToAddress("0x00000000000000000000000000000000deadbeef"), |
|
|
|
Coinbase: common.HexToAddress("0x00000000000000000000000000000000deadbeef"), |
|
|
|