Skip to content

Commit

Permalink
Tests: Reduce amount of nesting in benchmarking JSON output
Browse files Browse the repository at this point in the history
Signed-off-by: Hanno Becker <[email protected]>
  • Loading branch information
hanno-becker committed Jan 1, 2025
1 parent ceea1f5 commit f331ee4
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions scripts/lib/mlkem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,34 +277,33 @@ def bench(self):

# NOTE: There will only be one items in resultss, as we haven't yet decided how to write both opt/no-opt benchmark results
for k, results in resultss.items():
if results is not None and output is not None and components is False:
import json

with open(output, "w") as f:
v = []
for scheme in results:
schemeStr = str(scheme)
r = results[scheme]

# The first 3 lines of the output are expected to be
# keypair cycles=X
# encaps cycles=X
# decaps cycles=X

lines = [line for line in r.splitlines() if "=" in line]

d = {
k.strip(): int(v) for k, v in (l.split("=") for l in lines)
if not (results is not None and output is not None and components is False):
continue

v = []
for scheme in results:
schemeStr = str(scheme)
r = results[scheme]

# The first 3 lines of the output are expected to be
# keypair cycles=X
# encaps cycles=X
# decaps cycles=X

lines = [line for line in r.splitlines() if "=" in line]

d = {k.strip(): int(v) for k, v in (l.split("=") for l in lines)}
for primitive in ["keypair", "encaps", "decaps"]:
v.append(
{
"name": f"{schemeStr} {primitive}",
"unit": "cycles",
"value": d[f"{primitive} cycles"],
}
for primitive in ["keypair", "encaps", "decaps"]:
v.append(
{
"name": f"{schemeStr} {primitive}",
"unit": "cycles",
"value": d[f"{primitive} cycles"],
}
)
f.write(json.dumps(v))
)

with open(output, "w") as f:
f.write(json.dumps(v))

def all(self):
func = self.args.func
Expand Down

0 comments on commit f331ee4

Please sign in to comment.