File: preprocessed_file_size_stats_diff.py

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (46 lines) | stat: -rwxr-xr-x 1,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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()