kirr has posted comments on this change by kirr. ( https://gerrit.osmocom.org/c/osmocom-bb/+/39536?usp=email ) Change subject: trx_toolkit/*: Represent bursts as arrays instead of lists ...................................................................... Patch Set 2: (2 comments) Patchset: PS2: Thanks for review and merging. File src/target/trx_toolkit/data_msg.py: https://gerrit.osmocom.org/c/osmocom-bb/+/39536/comment/559e8473_188bb5d9?us... : PS2, Line 31: struct.unpack('b', struct.pack('B', x))[0]
Alternatively, we could use `int.to_bytes()` / `int.from_bytes()` API here: […] Performance does not matter here at all as _bu2s is used only at import time to construct `_tab_sbit2usbit` and `_tab_sbit2ubit` tables.
But anyway here is performance comparision of this two approaches: ``` In [2]: def _bu2s(x): ...: return struct.unpack('b', struct.pack('B', x))[0] ...: In [3]: def V_bu2s(x): return int.from_bytes(x.to_bytes(1), signed=True) In [6]: _bu2s(0x81) Out[6]: -127 In [7]: V_bu2s(0x81) Out[7]: -127 In [8]: %timeit _bu2s(0x81) 137 ns ± 1.21 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) In [9]: %timeit V_bu2s(0x81) 162 ns ± 1.42 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) ``` so struct-based variant works a bit faster. -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/39536?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I7314e9e79752e06fa86b9e346a9beacc5e59579e Gerrit-Change-Number: 39536 Gerrit-PatchSet: 2 Gerrit-Owner: kirr <kirr@nexedi.com> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> Gerrit-Reviewer: pespin <pespin@sysmocom.de> Gerrit-CC: osmith <osmith@sysmocom.de> Gerrit-Comment-Date: Tue, 25 Feb 2025 12:54:41 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: fixeria <vyanitskiy@sysmocom.de>