From d7312d8b048151d0742fd58e474f26f2d9ed876b Mon Sep 17 00:00:00 2001 From: Leon Morten Richter Date: Sat, 28 Sep 2024 13:32:13 +0200 Subject: [PATCH] chore: adds bench.py --- examples/bench.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/bench.py diff --git a/examples/bench.py b/examples/bench.py new file mode 100644 index 0000000..f2035a4 --- /dev/null +++ b/examples/bench.py @@ -0,0 +1,20 @@ +import pathlib +import time +from collections import defaultdict +from pyais import FileReaderStream +from pyais.exceptions import UnknownMessageException + +file = pathlib.Path(__file__).parent.joinpath('../tests/nmea-sample') +stats = defaultdict(lambda: 0) +start = time.time() + +for i, msg in enumerate(FileReaderStream(file), 1): + try: + decoded = msg.decode() + stats[decoded.msg_type] += 1 + except UnknownMessageException: + stats['errors'] += 1 + + +print(stats) +print(f'Decoded {i} NMEA AIS messages in {time.time() - start: .2f}s')