Skip to content

Speed up GOD processing

Gerhard Raven requested to merge faster-god into master

has_key is not only deprecated in python 3, but it is also slower:

% python -mtimeit -s'd=dict.fromkeys(range(99))' '12 in d'
10000000 loops, best of 3: 0.0342 usec per loop
% python -mtimeit -s'd=dict.fromkeys(range(99))' 'd.has_key(12)'
10000000 loops, best of 3: 0.0657 usec per loop
% python -mtimeit -s'd=dict.fromkeys(range(9999))' '12 in d'
10000000 loops, best of 3: 0.0346 usec per loop
% python -mtimeit -s'd=dict.fromkeys(range(9999))' 'd.has_key(12)'
10000000 loops, best of 3: 0.0661 usec per loop

As a result, this commit replaces every d.has_key(k) with k in d. In addition, constructions like

if d.has_key(k):
     for i in d[k]:

are replaced with:

for i in d.get(k,[])

For a full re-build of LHCb, this seems to save more than 10% of the total build time on our local cluster

Edited by Marco Cattaneo

Merge request reports

Loading