Created
November 30, 2011 20:00
-
-
Save j2labs/1410555 to your computer and use it in GitHub Desktop.
imports happen once
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import time | |
>>> def time_it(fun): | |
... start = time.time() | |
... fun() | |
... end = time.time() | |
... print 'Time:', end - start | |
... | |
>>> def foo(): | |
... import logging | |
... import multiprocessing | |
... import thread | |
... | |
>>> def bar(): | |
... import logging | |
... import multiprocessing | |
... import thread | |
... | |
>>> time_it(foo) | |
Time: 0.0508568286896 | |
>>> time_it(foo) | |
Time: 1.4066696167e-05 | |
>>> time_it(foo) | |
Time: 1.28746032715e-05 | |
>>> time_it(foo) | |
Time: 1.28746032715e-05 | |
>>> time_it(bar) | |
Time: 1.31130218506e-05 | |
>>> time_it(bar) | |
Time: 1.28746032715e-05 | |
>>> time_it(bar) | |
Time: 1.28746032715e-05 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment