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.