Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created November 30, 2011 20:00
Show Gist options
  • Save j2labs/1410555 to your computer and use it in GitHub Desktop.
Save j2labs/1410555 to your computer and use it in GitHub Desktop.
imports happen once
>>> 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