Commit
3bfe82ac0e7af14fd0142952331ca56f094c3841
by Kirill Smelkovtrx_toolkit/*: Represent bursts as arrays instead of lists
Continuing fake_trx profiling story I noticed that on rx path a
noticeable time is spent in converting from ubits to sbits via list
comprehensions. By changing burst representation from py list, which
stores each item as full python object, to an array, which stores each
item as just byte, and by leveraging bytearray.translate, we can sped
that conversion by ~ 10x:
before:
In [1]: from data_msg import Msg
In [2]: burst = [0, 1] * (142//2)
In [3]: burst
Out[3]:
[0,
1,
0,
1,
0,
...
0,
1]
In [4]: Msg.ubit2sbit(burst)
Out[4]:
[127,
-127,
127,
-127,
...
127,
-127]
In [5]: %timeit Msg.ubit2sbit(burst)
3.01 µs ± 43.3 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
after:
In [2]: burst = bytearray([0, 1] * (142//2))
In [3]: burst
Out[3]: bytearray(b'\x00\x01\x00\x01...\x00\x01')
In [4]: Msg.ubit2sbit(burst)
Out[4]: array('b', [127, -127, 127, -127, ... 127, -127])
In [5]: %timeit Msg.ubit2sbit(burst)
325 ns ± 12.1 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
Change-Id: I7314e9e79752e06fa86b9e346a9beacc5e59579e