I have written Python scripts with the command line, but lately I have really been disappointed in speed.
I'm not necessarily talking about processing speed, task dispatching, or other processes that depend on the command line (usually this is a design / implementation problem), but I'm just talking about launching a tool to get the help menu, or display minimal information.
As an example, Mercurial has a value of about 0.080scs, and GIT has a value of 0.030scs.
I have studied the Mercurial source code (it's still Python), but the response to the quick response script still eludes me.
I think imports and the way you manage them is a big reason for the initial slowdown. But is there any best practice for fast, responsive command line scripts in Python?
One Python script that imports os and optparse and executes main () to parse some argument parameters takes 0.160scs on my machine just to display the help menu ...
This is 5 times slower than just starting git!
Edit:
I shouldn't have mentioned GIT as it is written in C. But the Mercurial part is still standing, and no, pyc don't feel much improvement (at least for me).
Edit 2:
Although lazy imports are the key to speeding up in Mercurial, they reduced to regular Python scripts do not have automatically generated scripts with pkg_resources in them, for example:
from pkg_resources import load_entry_point
If you manually created scripts that do not use pkg_resources, you should see at least a 2-speed increase.
But! Be careful that pkg_resources provides a great way to version dependencies, so make sure you know that not using it basically means possible version conflicts.