Skip to content

Commit

Permalink
Decoded string, and added new regest to match µs
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-dc committed Dec 17, 2019
1 parent 1e1dfda commit 4b9825d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions evm/scripts/benchevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,25 @@ def do_geth_bench(geth_cmd):
print("running geth-evm benchmark...\n{}\n".format(geth_cmd))
geth_cmd = shlex.split(geth_cmd)
stdoutlines = []
with subprocess.Popen(geth_cmd, cwd=GETH_EVM_DIR, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) as p:
with subprocess.Popen(geth_cmd, cwd=GETH_EVM_DIR, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1) as p:
for line in p.stdout: # b'\n'-separated lines
print(line, end='')
stdoutlines.append(line) # pass bytes as is
print(line.decode(), end='')
stdoutlines.append(line.decode()) # pass bytes as is
p.wait()

nsOpRegex = "evm execution time: ([\d]+.[\d]+)ms"
msOpRegex = "evm execution time: ([\d]+.[\d]+)ms"
qsOpRegex = "evm execution time: ([\d]+.[\d]+)µs"
gasregex = "Gas used:\s+(\d+)"
# maybe --benchmark_format=json is better so dont have to parse "36.775k"
time_line = stdoutlines[0]
gas_line = stdoutlines[-3]
time_match = re.search(nsOpRegex, time_line)
time = durationpy.from_str("{}ms".format(time_match.group(1)))
time_match = re.search(msOpRegex, time_line)
time = None
if time_match == None:
time_match = re.search(qsOpRegex, time_line)
time = durationpy.from_str("{}µs".format(time_match.group(1)))
else:
time = durationpy.from_str("{}ms".format(time_match.group(1)))
gas_match = re.search(gasregex, gas_line)
gasused = gas_match.group(1)
return {'gas_used': gasused, 'time': time.total_seconds()}
Expand Down

0 comments on commit 4b9825d

Please sign in to comment.