2 comments:
Patchset:
Thanks for review and merging.
File src/target/trx_toolkit/data_msg.py:
Patch Set #2, 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 change 39536. To unsubscribe, or for help writing mail filters, visit settings.