Does importing a Python module affect performance?
<p>When searching for a solution, it's common to come across several methods. I often use the solution that most closely aligns with syntax I'm familiar with. But sometimes the far-and-away most upvoted solution involves importing a module new to me, as in <a href="http://stackoverflow.com/questions/613183/sort-a-python-dictionary-by-value">this thread</a>.</p>

<p>I'm already importing various modules in large script that will be looping 50K times. Does importing additional modules affect processing time, or otherwise affect the script's efficiency? Do I need to worry about the size of the module being called? Seeking guidance on whether, generally, it's worth the extra time/effort to find solutions using methods contained in modules I'm already using.</p>

<p>Every bytecode in Python affects performance. However, unless that code is on a critical path and repeated a high number of times, the effect is so small as to not matter.</p>

<p>Using <code>import</code> consists of two distinct steps: loading the module (done just <em>once</em>), and binding names (where the imported name is added to your namespace to refer to something loaded by the module, or the module object itself). Binding names is almost costless. Because loading a module happens just once, it won't affect your performance.</p>

<p>Focus instead on what the module functionality can do to help you solve your problem efficiently.</p>

python import module