python - Import statement affects script performance -


i reviewing code , updating import statements based on general guidelines, changing “from xxx import *” “from xxx import m, n, p”. difference in script execution time, however, noticeable:

from collections import ordereddict definitions import * 

average script time 22ms

from collections import ordereddict definitions import a, b, c, d, e, f 

average script time 48ms

the topic of import performance has been taken several times on se, , these results seem run counter answers. why import statement in case cause such significant difference in script performance?

a follow-up question: package uses "definitions.py" store package general purpose (mostly static) classes , functions. best way import classes module, without needing prefix "definitions." every time used?

edit more information... curiouser , curiouser

script timing done using time.clock() on >50 iterations

it turns out ordereddict imported in definitions, when import there script time down:

from definitions import a, b, c, d, e, f, ordereddict 

average script time 22ms

just thicken plot, there "from system import array" statement though has no effect on script time. way script imports ordereddict appears issue.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -