Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
d8aaa3a2
Unverified
Commit
d8aaa3a2
authored
7 years ago
by
Martin Holst Swende
Committed by
Péter Szilágyi
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/vm: benchmarking of metro precompiles
parent
6131dd55
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
341 additions
and
206 deletions
+341
-206
contracts_test.go
core/vm/contracts_test.go
+302
-86
instructions_test.go
core/vm/instructions_test.go
+39
-120
No files found.
core/vm/contracts_test.go
View file @
d8aaa3a2
This diff is collapsed.
Click to expand it.
core/vm/instructions_test.go
View file @
d8aaa3a2
package
vm
import
(
"fmt"
"math/big"
"testing"
...
...
@@ -64,126 +63,44 @@ func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contr
}
}
func
precompiledBenchmark
(
addr
,
input
,
expected
string
,
gas
uint64
,
bench
*
testing
.
B
)
{
func
BenchmarkOpAdd64
(
b
*
testing
.
B
)
{
x
:=
"ffffffff"
y
:=
"fd37f3e2bba2c4f"
contract
:=
NewContract
(
AccountRef
(
common
.
HexToAddress
(
"1337"
)),
nil
,
new
(
big
.
Int
),
gas
)
p
:=
PrecompiledContractsMetropolis
[
common
.
HexToAddress
(
addr
)]
in
:=
common
.
Hex2Bytes
(
input
)
var
(
res
[]
byte
err
error
)
data
:=
make
([]
byte
,
len
(
in
))
bench
.
ResetTimer
()
for
i
:=
0
;
i
<
bench
.
N
;
i
++
{
contract
.
Gas
=
gas
copy
(
data
,
in
)
res
,
err
=
RunPrecompiledContract
(
p
,
data
,
contract
)
}
bench
.
StopTimer
()
//Check if it is correct
if
err
!=
nil
{
bench
.
Error
(
err
)
return
}
if
common
.
Bytes2Hex
(
res
)
!=
expected
{
bench
.
Error
(
fmt
.
Sprintf
(
"Expected %v, got %v"
,
expected
,
common
.
Bytes2Hex
(
res
)))
return
}
}
func
BenchmarkPrecompiledECDSA
(
bench
*
testing
.
B
)
{
var
(
addr
=
"01"
inp
=
"38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp
=
"000000000000000000000000ceaccac640adf55b2028469bd36ba501f28b699d"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
}
func
BenchmarkPrecompiledSha256
(
bench
*
testing
.
B
)
{
var
(
addr
=
"02"
inp
=
"38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp
=
"811c7003375852fabd0d362e40e68607a12bdabae61a7d068fe5fdd1dbbf2a5d"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
opBenchmark
(
b
,
opAdd
,
x
,
y
)
}
func
BenchmarkPrecompiledRipeMD
(
bench
*
testing
.
B
)
{
var
(
addr
=
"03"
inp
=
"38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp
=
"0000000000000000000000009215b8d9882ff46f0dfde6684d78e831467f65e6"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
}
func
BenchmarkOpAdd128
(
b
*
testing
.
B
)
{
x
:=
"ffffffffffffffff"
y
:=
"f5470b43c6549b016288e9a65629687"
func
BenchmarkPrecompiledIdentity
(
bench
*
testing
.
B
)
{
var
(
addr
=
"04"
inp
=
"38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp
=
"38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
opBenchmark
(
b
,
opAdd
,
x
,
y
)
}
func
BenchmarkPrecompiledModExp
(
bench
*
testing
.
B
)
{
var
(
addr
=
"05"
inp
=
"00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"
exp
=
"0000000000000000000000000000000000000000000000000000000000000001"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
}
func
BenchmarkOpAdd256
(
b
*
testing
.
B
)
{
x
:=
"0802431afcbce1fc194c9eaa417b2fb67dc75a95db0bc7ec6b1c8af11df6a1da9"
y
:=
"a1f5aac137876480252e5dcac62c354ec0d42b76b0642b6181ed099849ea1d57"
func
BenchmarkPrecompiledBn256Add
(
bench
*
testing
.
B
)
{
var
(
addr
=
"06"
inp
=
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
exp
=
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
opBenchmark
(
b
,
opAdd
,
x
,
y
)
}
func
BenchmarkPrecompiledBn256ScalarMul
(
bench
*
testing
.
B
)
{
var
(
addr
=
"07"
inp
=
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
exp
=
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
}
func
BenchmarkOpSub64
(
b
*
testing
.
B
)
{
x
:=
"51022b6317003a9d"
y
:=
"a20456c62e00753a"
func
BenchmarkPrecompiledBn256Pairing
(
bench
*
testing
.
B
)
{
var
(
addr
=
"08"
inp
=
"1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa"
exp
=
"0000000000000000000000000000000000000000000000000000000000000001"
gas
=
uint64
(
4000000
)
)
precompiledBenchmark
(
addr
,
inp
,
exp
,
gas
,
bench
)
opBenchmark
(
b
,
opSub
,
x
,
y
)
}
func
BenchmarkOp
Add
(
b
*
testing
.
B
)
{
x
:=
"
ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff
"
y
:=
"
ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff
"
func
BenchmarkOp
Sub128
(
b
*
testing
.
B
)
{
x
:=
"
4dde30faaacdc14d00327aac314e915d
"
y
:=
"
9bbc61f5559b829a0064f558629d22ba
"
opBenchmark
(
b
,
op
Add
,
x
,
y
)
opBenchmark
(
b
,
op
Sub
,
x
,
y
)
}
func
BenchmarkOpSub
(
b
*
testing
.
B
)
{
x
:=
"
ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff
"
y
:=
"
ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff
"
func
BenchmarkOpSub
256
(
b
*
testing
.
B
)
{
x
:=
"
4bfcd8bb2ac462735b48a17580690283980aa2d679f091c64364594df113ea37
"
y
:=
"
97f9b1765588c4e6b69142eb00d20507301545acf3e1238c86c8b29be227d46e
"
opBenchmark
(
b
,
opSub
,
x
,
y
)
}
...
...
@@ -195,16 +112,27 @@ func BenchmarkOpMul(b *testing.B) {
opBenchmark
(
b
,
opMul
,
x
,
y
)
}
func
BenchmarkOpDiv
(
b
*
testing
.
B
)
{
x
:=
"ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
y
:=
"ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
func
BenchmarkOpDiv256
(
b
*
testing
.
B
)
{
x
:=
"ff3f9014f20db29ae04af2c2d265de17"
y
:=
"fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
opBenchmark
(
b
,
opDiv
,
x
,
y
)
}
func
BenchmarkOpDiv128
(
b
*
testing
.
B
)
{
x
:=
"fdedc7f10142ff97"
y
:=
"fbdfda0e2ce356173d1993d5f70a2b11"
opBenchmark
(
b
,
opDiv
,
x
,
y
)
}
func
BenchmarkOpDiv64
(
b
*
testing
.
B
)
{
x
:=
"fcb34eb3"
y
:=
"f97180878e839129"
opBenchmark
(
b
,
opDiv
,
x
,
y
)
}
func
BenchmarkOpSdiv
(
b
*
testing
.
B
)
{
x
:=
"
ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff
"
y
:=
"
ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff
"
x
:=
"
ff3f9014f20db29ae04af2c2d265de17
"
y
:=
"
fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611
"
opBenchmark
(
b
,
opSdiv
,
x
,
y
)
}
...
...
@@ -315,12 +243,3 @@ func BenchmarkOpMulmod(b *testing.B) {
opBenchmark
(
b
,
opMulmod
,
x
,
y
,
z
)
}
//func BenchmarkOpSha3(b *testing.B) {
// x := "0"
// y := "32"
//
// opBenchmark(b,opSha3, x, y)
//
//
//}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment