I want to know how much time an import takes for both built-in as well as user defined modules.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
To find out how long an import takes, the simplest way is probably using the timeit module..
So to import urllib 1 million times, it took just under a second (on a Macbook Pro)..
If you mean the total script execution time, on Linux/OS X/Cygwin, you can run the script using the
time
command, for example:(remember that includes all the Python interpreter startup time, as well as the actual code execution time, although it's pretty trivial amount)
Another, possibly more useful way is to profile the script:
Instead of running your code with
..you use..
I don't find the command line output very easy to read, so I almost always use gprof2dot, which turns the profiling information into a pretty graphviz graph:
Example output (1429x1896px PNG)