kirr has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmocom-bb/+/40044?usp=email )
Change subject: trx_toolkit/burst_fwd: Use 'is' instead of '==' when
checking if trx is src_trx
......................................................................
trx_toolkit/burst_fwd: Use 'is' instead of '==' when checking if trx is
src_trx
In python `a is b` is just a pointer comparison of locations of objects
a and b, while `a == b` can involve doing arbitrary code invoking __eq__
and is generally slower even without __eq__ defined:
In [1]: class A:
...: pass
...:
In [2]: a = A()
In [4]: b = A()
In [5]: a == a
Out[5]: True
In [6]: a == b
Out[6]: False
In [7]: a is a
Out[7]: True
In [8]: a is b
Out[8]: False
In [9]: %timeit a is a
84.2 ns ± 0.133 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [10]: %timeit a is b
87.5 ns ± 0.0736 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [11]: %timeit a == a
100 ns ± 0.659 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [12]: %timeit a == b
116 ns ± 0.399 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
BurstForwarder.forward_msg is one of the hottest places, as e.g. for every
received packet from BTS it forwards it to multiple Ms receivers. It
makes sense to be careful and save cycles here.
Change-Id: Ic9e16720daeb348b5f9c535c24a682db53a93529
---
M src/target/trx_toolkit/burst_fwd.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/44/40044/1
diff --git a/src/target/trx_toolkit/burst_fwd.py b/src/target/trx_toolkit/burst_fwd.py
index 6924531..e3da9c2 100644
--- a/src/target/trx_toolkit/burst_fwd.py
+++ b/src/target/trx_toolkit/burst_fwd.py
@@ -52,7 +52,7 @@
# Iterate over all known transceivers
for trx in self.trx_list:
- if trx == src_trx:
+ if trx is src_trx:
continue
# Check transceiver state
--
To view, visit
https://gerrit.osmocom.org/c/osmocom-bb/+/40044?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Ic9e16720daeb348b5f9c535c24a682db53a93529
Gerrit-Change-Number: 40044
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>