summaryrefslogtreecommitdiff
path: root/src/app/deflatetest/benchmark.py
blob: 379b62f2116460358985f6b498d4608095c9e63d (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3

import numpy as np
import re
import subprocess
import sys


def main(make_args):
    make_args += ["app=deflatetest"]
    base_rom = None
    base_ram = None
    defl_rom = None
    defl_ram = None
    defl_ms = None
    defl_size = None

    status = subprocess.run(
        ["./mp"] + make_args + ["deflate_nop=1"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        universal_newlines=True,
    )

    for line in status.stdout.split("\n"):
        match = re.search(r"ROM: (\d+) .* RAM: (\d+)", line)
        if match:
            base_rom = int(match.group(1))
            base_ram = int(match.group(2))
        match = re.match(r"Program: *(\d+) bytes", line)
        if match:
            base_rom = int(match.group(1))
        match = re.match(r"Data: *(\d+) bytes", line)
        if match:
            base_ram = int(match.group(1))

    status = subprocess.run(
        ["./mp"] + make_args,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        universal_newlines=True,
    )

    for line in status.stdout.split("\n"):
        match = re.search(r"ROM: (\d+) .* RAM: (\d+)", line)
        if match:
            defl_rom = int(match.group(1))
            defl_ram = int(match.group(2))
        match = re.match(r"Program: *(\d+) bytes", line)
        if match:
            defl_rom = int(match.group(1))
        match = re.match(r"Data: *(\d+) bytes", line)
        if match:
            defl_ram = int(match.group(1))

    rom_usage = int(np.ceil((defl_rom - base_rom) / 16)) * 16
    ram_usage = int(np.ceil((defl_ram - base_ram) / 16)) * 16
    arch_line = " ".join(make_args)
    print(f"| {arch_line} | {rom_usage} B | {ram_usage} B")

    status = subprocess.run(
        ["make", "cat"] + make_args, stdout=subprocess.PIPE, universal_newlines=True
    )

    for line in status.stdout.split("\n"):
        match = re.match(r"took ([0-9.]+) ms", line)
        if match:
            defl_ms = float(match.group(1))
        match = re.match(r"inflate returned (\d+)", line)
        if match:
            defl_size = int(match.group(1))

    defl_speed = defl_size / defl_ms
    print(f"{defl_speed:3.0f} kB/s    ({defl_size:4d} B @ {defl_ms:6.2f} ms)")


if __name__ == "__main__":
    main(sys.argv[1:])