Skip to content

Instantly share code, notes, and snippets.

@bluss
Last active November 19, 2017 21:31
Show Gist options
  • Save bluss/d8d65ecb093fa324de77eb145e83cee8 to your computer and use it in GitHub Desktop.
Save bluss/d8d65ecb093fa324de77eb145e83cee8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import sys
import functools
import re
from collections import namedtuple, OrderedDict
Rec = namedtuple("Rec", "name time line")
def file_to_records(filename):
res = OrderedDict()
r = re.compile(r"test (.*)\.\.\. bench:\s+(.*) ns/iter")
with open(filename) as fp:
for line in fp:
m = r.match(line)
if m is not None:
time_number = int(m.group(2).replace(",", ""))
name = m.group(1).strip()
res[name] = Rec(line=line, name=name, time=time_number)
return res
def main(filenames):
records = [file_to_records(fn) for fn in filenames]
result = functools.reduce(merge, records)
for records in result.values():
print(records.line, end="")
def merge(rec1, rec2):
for k2, v2 in rec2.items():
if k2 not in rec1:
rec1[k2] = v2
elif rec1[k2].time > v2.time:
rec1[k2] = v2
return rec1
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment