Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precompiles benchmark #5

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
70 changes: 70 additions & 0 deletions scripts/postprocess_nethermind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/python

import sys
from tabulate import tabulate

ECRECOVER_GAS_COST = 3000
BILLION = 1000000000
ECRECOVER_TEST_NAME = 'ValidKey'


def parse_line(line):
splitted = line.split(',')
benchmark = splitted[0]
name = splitted[1]
nominalGasCost = splitted[2]
memGcOps = splitted[5]
memAllocOps = splitted[6]
time_ns = int(float(splitted[4]))
# example line: PointEvaluationBenchmark,fuzzcorp-33,50000,3,1260260.546875,512,185
return (benchmark, name, nominalGasCost, memGcOps, memAllocOps, time_ns)


def compare_with_ecrecover(f):
items = []
lines = f.split("\n")
ecdsa_gas_per_second = 0

# first pass to find the values for the ecdsarecover
for line in lines[5:]:
if len(line) > 0:
(_benchmark, name, nominalGasCost, memGcOps, memAllocOps, time_ns) = parse_line(line)
if name == ECRECOVER_TEST_NAME:
ecdsa_gas_cost_per_second = (BILLION * ECRECOVER_GAS_COST) / time_ns

# benchamrk results start from line 6
for line in lines[5:]:
if len(line) > 0:
(benchmark, name, nominalGasCost, memGcOps, memAllocOps, time_ns) = parse_line(line)
ecdsa_equivalent = (ecdsa_gas_cost_per_second * time_ns) / BILLION
item = [benchmark, name, nominalGasCost, time_ns, memGcOps, memAllocOps, ecdsa_equivalent]
items.append(item)
print("```")
print(tabulate(items, headers=['Benchmark', 'Name', 'Nominal Gas Cost', 'Time (ns)', 'GC Ops', 'Mem Alloc Ops', 'Gas Cost for ECDSA eq'], tablefmt="github", floatfmt=".2f"))
print("```")
print("""
Columns
* `Gasprice for ECDSA eq` shows what the gasprice whould be if it had the same cost/cycle as ecRecover
""")

def test():
t = """Benchmark Process Environment Information:
Runtime=.NET 6.0.10 (6.0.1022.47605), X64 RyuJIT
GC=Concurrent Workstation

Benchmark,Test,NominalGasCost,RunsCount,TimeNs,MemGcOps,MemAllocPerOp
EcRecoverBenchmark,ValidKey,3000,3,60522.774251302086,16384,424
PointEvaluationBenchmark,fuzzcorp-33,50000,3,1260260.546875,512,185
PointEvaluationBenchmark,fuzzcorp-95,50000,3,1263063.4114583333,512,185
PointEvaluationBenchmark,pointEvaluation1,50000,3,1246459.1145833333,512,185"""
postprocess(t)

if __name__ == '__main__':
#test()

if len(sys.argv) < 2:
print("usage : postprocess_nethermind <file>")
sys.exit(1)

with open(sys.argv[1]) as f:
compare_with_ecrecover(f.read())
195 changes: 195 additions & 0 deletions shanghai/2023-01-16/README.md

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions shanghai/2023-01-16/rawdata/besu_bytecode_win_jacek.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
EcRecover - ValidKey
{"gasUser":"0xc62","timens":255513,"time":255,"gasTotal":"0xc62","output":"0x"}

Bn256Add-Valid
{"gasUser":"0x140","timens":110211,"time":110,"gasTotal":"0x140","output":"0x"}

Bn256Mul-Valid
{"gasUser":"0x180e","timens":187487,"time":187,"gasTotal":"0x180e","output":"0x"}

Bn256Pairing-1
{"gasUser":"0x1355a","timens":1389150,"time":1389,"gasTotal":"0x1355a","output":"0x"}

Bn256Pairing-2
{"gasUser":"0x1ba72","timens":1936933,"time":1936,"gasTotal":"0x1ba72","output":"0x"}

Bn256Pairing-4
{"gasUser":"0x2c4a3","timens":3081944,"time":3081,"gasTotal":"0x2c4a3","output":"0x"}

Bn256Pairing-8
{"gasUser":"0x4d906","timens":5493774,"time":5493,"gasTotal":"0x4d906","output":"0x"}

pointEvaluation1
{"gasUser":"0xcdd6","timens":1056739,"time":1056,"gasTotal":"0xcdd6","output":"0x"}

PointEvaluation fuzzcorp-33
{"gasUser":"0xcdd6","timens":1670175,"time":1670,"gasTotal":"0xcdd6","output":"0x"}

PointEvaluation fuzzcorp-95
{"gasUser":"0xcdd6","timens":1629470,"time":1629,"gasTotal":"0xcdd6","output":"0x"}

Sha256 scalar_128
{"gasUser":"0x116","timens":127921,"time":127,"gasTotal":"0x116","output":"0x"}

Sha256 scalar_256
{"gasUser":"0x176","timens":113927,"time":113,"gasTotal":"0x176","output":"0x"}

RipeMd scalar_128
{"gasUser":"0x37a","timens":150690,"time":150,"gasTotal":"0x37a","output":"0x"}

RipeMd scalar_256
{"gasUser":"0x6f2","timens":210298,"time":210,"gasTotal":"0x6f2","output":"0x"}

20 changes: 20 additions & 0 deletions shanghai/2023-01-16/rawdata/erigon_bytecode_win_jacek.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
goos: windows
goarch: amd64
pkg: github.com/ledgerwatch/erigon/core/vm/runtime
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkBytecodePrecompile/EcRecover/ValidKey-16 14862 77027 ns/op 3000 nominalGas/op 4884 B/op 80 allocs/op
BenchmarkBytecodePrecompile/Bn256Add/Bn256Add-Valid-16 39734 30550 ns/op 150.0 nominalGas/op 5584 B/op 92 allocs/op
BenchmarkBytecodePrecompile/Bn256Mul/Bn256Mul-Valid-16 10000 135819 ns/op 6000 nominalGas/op 6216 B/op 104 allocs/op
BenchmarkBytecodePrecompile/Bn256Pairing/Bn256Pairing-1-16 666 1661813 ns/op 79000 nominalGas/op 60314 B/op 578 allocs/op
BenchmarkBytecodePrecompile/Bn256Pairing/Bn256Pairing-2-16 417 2731387 ns/op 113000 nominalGas/op 109967 B/op 1057 allocs/op
BenchmarkBytecodePrecompile/Bn256Pairing/Bn256Pairing-4-16 266 4194409 ns/op 181000 nominalGas/op 209188 B/op 2012 allocs/op
BenchmarkBytecodePrecompile/Bn256Pairing/Bn256Pairing-8-16 140 8348450 ns/op 317000 nominalGas/op 409112 B/op 3920 allocs/op
BenchmarkBytecodePrecompile/PointEvaluation/pointEvaluation1-16 866 1293137 ns/op 50000 nominalGas/op 59885 B/op 429 allocs/op
BenchmarkBytecodePrecompile/PointEvaluation/fuzzcorp-33-16 5290 205447 ns/op 50000 nominalGas/op 24743 B/op 219 allocs/op
BenchmarkBytecodePrecompile/PointEvaluation/fuzzcorp-95-16 5356 210143 ns/op 50000 nominalGas/op 24740 B/op 219 allocs/op
BenchmarkBytecodePrecompile/Sha256/scalar_128-16 68838 16919 ns/op 108.0 nominalGas/op 4714 B/op 77 allocs/op
BenchmarkBytecodePrecompile/Sha256/scalar_256-16 54631 18704 ns/op 156.0 nominalGas/op 5322 B/op 78 allocs/op
BenchmarkBytecodePrecompile/RipeMd/scalar_128-16 61813 16903 ns/op 1080 nominalGas/op 4867 B/op 78 allocs/op
BenchmarkBytecodePrecompile/RipeMd/scalar_256-16 55581 19706 ns/op 1560 nominalGas/op 5337 B/op 79 allocs/op
PASS
ok github.com/ledgerwatch/erigon/core/vm/runtime 33.921s
Loading