You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw/scripts/preprocessed_file_size_stat...

47 lines
1.3 KiB
Python

#!/usr/bin/env python3
import click
import json
import termtables
@click.command()
@click.argument('first', type=click.Path(exists=True))
@click.argument('second', type=click.Path(exists=True))
def main(first, second):
stats = tuple(read_stats(v) for v in (first, second))
keys = set()
for v in stats:
keys.update(v.keys())
keys = sorted(keys - {'total'})
result = list()
for k in keys:
first_size = stats[0].get(k, 0)
second_size = stats[1].get(k, 0)
diff = second_size - first_size
if diff != 0:
result.append((k, first_size, diff, (second_size / first_size - 1) * 100 if first_size != 0 else 100))
result.sort(key=lambda v: tuple(reversed(v)))
diff = stats[1]['total'] - stats[0]['total']
first_total = stats[0]['total']
result.append(('total', first_total, diff, (stats[1]['total'] / first_total - 1) * 100) if first_total != 0 else 100)
print(f'Preprocessed code size diff between {first} and {second}:\n')
termtables.print(
[(v[0], v[1], f'{v[2]:+}', f'{v[3]:+}') for v in result],
header=['file', 'size, bytes', 'diff, bytes', 'diff, %'],
style=termtables.styles.markdown,
)
def read_stats(path):
with open(path) as stream:
return json.load(stream)
if __name__ == '__main__':
main()