| 1 |
import operator |
| 2 |
import re |
| 3 |
|
| 4 |
_parse_result_line = re.compile( |
| 5 |
r"\s*(?P<library>\w+):\s*(?P<name>\w+)\s+\((?P<config>[-\w]+\s[\w,]+)\s*\)\s+(?P<time>[0-9.]+\s+msec/pass)" |
| 6 |
).match |
| 7 |
|
| 8 |
_make_key = operator.itemgetter('library', 'name', 'config') |
| 9 |
|
| 10 |
|
| 11 |
def read_benchmark_results(benchmark_files): |
| 12 |
benchmark_results = {} |
| 13 |
for file_path in benchmark_files: |
| 14 |
with open(file_path) as f: |
| 15 |
for line in f: |
| 16 |
result = _parse_result_line(line) |
| 17 |
if not result: |
| 18 |
continue |
| 19 |
d = result.groupdict() |
| 20 |
benchmark_results[_make_key(d)] = d['time'] |
| 21 |
|
| 22 |
return benchmark_results |
| 23 |
|
| 24 |
|
| 25 |
def update_results(text_file, benchmark_results): |
| 26 |
with open(text_file) as f: |
| 27 |
for line in f: |
| 28 |
match = _parse_result_line(line) |
| 29 |
if not match: |
| 30 |
yield line |
| 31 |
continue |
| 32 |
|
| 33 |
d = match.groupdict() |
| 34 |
key = _make_key(d) |
| 35 |
try: |
| 36 |
new_time = benchmark_results[key] |
| 37 |
except KeyError: |
| 38 |
print("Failed to update benchmark results of %r" % d) |
| 39 |
yield line |
| 40 |
else: |
| 41 |
yield line.replace(d['time'], new_time) |
| 42 |
|
| 43 |
|
| 44 |
def main(log_files, doc_file="doc/performance.txt"): |
| 45 |
results = read_benchmark_results(log_files) |
| 46 |
if not results: |
| 47 |
return |
| 48 |
|
| 49 |
print("Found %d benchmark results" % len(results)) |
| 50 |
new_text = "".join(update_results(doc_file, results)) |
| 51 |
with open(doc_file, 'w') as f: |
| 52 |
f.write(new_text) |
| 53 |
print("Updated benchmark results in %s" % doc_file) |
| 54 |
|
| 55 |
|
| 56 |
if __name__ == '__main__': |
| 57 |
import sys |
| 58 |
main(sys.argv[1:]) |