Just wondering if importing more functions from other scripts slows down a script in general?
Some background:
I have two scripts, one that runs much faster than the other, one has an extra import statement at the top and extra function at the bottom, but its the stuff in the middle, thats the same between scripts that is running slower.
Starting a Python interpreter and importing Python modules is relatively slow if you care about milliseconds. If you need to start hundreds or thousands of Python processes as part of a workload, this overhead will amount to several seconds of overhead.
If your Python code runs too fast, a call to time. sleep() is a simple way to slow down your code.
Import order does not matter. If a module relies on other modules, it needs to import them itself. Python treats each . py file as a self-contained unit as far as what's visible in that file.
More information about your case, Import_Statement_Overhead:
Import statements can be executed just about anywhere. It's often useful to place them inside functions to restrict their visibility and/or reduce initial startup time. Although Python's interpreter is optimized to not import the same module multiple times, repeatedly executing an import statement can seriously affect performance in some circumstances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With