diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-01-24 17:25:50 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-01-24 17:25:50 +0100 |
commit | cd73b1220a2952e3bfd106090c61e546cca4cbcc (patch) | |
tree | 7bf13237ba8b6c3ef842d908411377dc01f0f95d /src/app/deflatetest/benchmark.py | |
parent | 572721143ae46d9a1b9a3b4119fdca481b963a20 (diff) |
deflatetest: add benchmark script
Diffstat (limited to 'src/app/deflatetest/benchmark.py')
-rwxr-xr-x | src/app/deflatetest/benchmark.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/app/deflatetest/benchmark.py b/src/app/deflatetest/benchmark.py new file mode 100755 index 0000000..c9fc968 --- /dev/null +++ b/src/app/deflatetest/benchmark.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import numpy as np +import re +import subprocess +import sys + + +def main(arch): + make_args = [f"arch={arch}", "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, + 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)) + + status = subprocess.run( + ["./mp"] + make_args, stdout=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)) + + rom_usage = int(np.ceil((defl_rom - base_rom) / 16)) * 16 + ram_usage = int(np.ceil((defl_ram - base_ram) / 16)) * 16 + print(f"| {arch} | {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:]) |