semuconsulting / pyubx2

Python library for parsing and generating UBX GPS/GNSS protocol messages.
BSD 3-Clause "New" or "Revised" License
165 stars 65 forks source link

Introduced dictionaries where keys and values are swapped. #39

Closed Hadatko closed 2 years ago

Hadatko commented 2 years ago

Get rid of construction to going trough dict values to find key.

Signed-off-by: Cervenka Dusan cervenka@acrios.com

pyubx2 Pull Request Template

Description

Hello, i was curious about your opinion on this update. Same as you are doing in your code, sometimes i need find dict key using dict value. I didn't know about function key_from_val but anyway i don't really like it as you are iterating trough dict.items() often (every call in my case)... I think this can be faster and simpler solution. Downside is more memory to use (as new dictionaries are created)

Fixes # (issue)

Testing

Please test all changes, however trivial, against the supplied unittest suite tests/test_*.py e.g. by executing the tests/testsuite.py module or using your IDE's native Python unittest integration facilities. Please describe any test cases you have amended or added to this suite to maintain >= 99% code coverage.

Checklist:

semuadmin commented 2 years ago

Hi @Hadatko

I've run some benchmark tests against your PR, results as follows:

Operating system: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 Python version: 3.10.0 pyubx2 version: 1.1.3 (CURRENT VERSION) Test cycles: 10,000

Executing benchmark test...

Benchmark test completed.

350,000 messages processed in 22.972 seconds = 15,235.67 txns/second.

Operating system: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 Python version: 3.10.0 pyubx2 version: 1.1.5 (YOUR DICT SWAP PR VERSION) Test cycles: 10,000

Executing benchmark test...

Benchmark test completed.

350,000 messages processed in 23.329 seconds = 15,002.94 txns/second.

I ran this a few times but could find no meaningful different in performance - if anything, your version is very slightly slower.

So, sorry, but I'm going to drop this one for now.

But do please keep the contributions coming. Many thanks.