Skip to content

Instantly share code, notes, and snippets.

@AdamG
Created July 28, 2012 13:23
Show Gist options
  • Save AdamG/3193380 to your computer and use it in GitHub Desktop.
Save AdamG/3193380 to your computer and use it in GitHub Desktop.
Inner Import Overhead
import timeit
setup = """
import sys as sys_module_level
def outer_test():
return sys_module_level.version_info
def inner_test():
import sys
return sys.version_info
"""
print "moduleimp:{}".format(min(timeit.repeat("outer_test()", setup, repeat=3, number=1024)))
print "innerimp: {}".format(min(timeit.repeat("inner_test()", setup, repeat=3, number=1024)))
# $ python ~/tmp/imptest.py
# moduleimp:0.000121831893921
# innerimp: 0.000499963760376
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment