Created
July 28, 2012 13:23
-
-
Save AdamG/3193380 to your computer and use it in GitHub Desktop.
Inner Import Overhead
This file contains 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 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