[apparmor] Python array types - speed comparison

Christian Boltz apparmor at cboltz.de
Sun Nov 20 15:58:02 UTC 2016


Hello,

just a small FYI after discussing this with Seth on IRC some days ago:

I did some speed comparisons for the various array types and defining 
them globally vs. in the function using the OP_TYPE_FILE_OR_NET array 
from=20the patch I just sent.

The results are:

# py3, 10000000 runs
 8.30721783638000 [] global
10.27099061012268 [] inside fn
 8.67911791801452 () global
 8.52981829643249 () inside fn
 5.45463919639587 {} global
14.80267071723938 {} inside fn

It's not too surprising that defining the array inside the function 
(which means to rebuild it each time the function is called) is slower, 
however it's not terribly bad (the times above are from 10 000 000 
runs!)

An interesting detail is that using (...) inside the function isn't 
slower than using it outside. (...) arrays are read-only, so python 
probably caches them after running the function the first time.

(...) and [...] keep the original sort order.
{...} doesn't care about the order. This seems to improve the lookup 
speed quite a bit (but also makes building the array slower).


If you want to check yourself - my test script is attached.

Yes, I know that the definition of the global arrays isn't included in 
the time measurement - but I'm quite sure this doesn't really change the 
results ;-)


Regards,

Christian Boltz
-- 
Wir waren vor einiger Zeit schonmal "soweit fertig". Dann kam
Gerald, fand 1000 Sachen Scheisse, hat 500 Sachen nicht begriffen
und 250 falsch gemacht. :-))))))   [Ratti in fontlinge-devel]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: array-speed.py
Type: text/x-python
Size: 8413 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20161120/840ccc32/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20161120/840ccc32/attachment.pgp>


More information about the AppArmor mailing list