Skip to content

Instantly share code, notes, and snippets.

@methane
Created June 21, 2017 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save methane/a75ff64289f0aad7e3690d0c8884e9e7 to your computer and use it in GitHub Desktop.
Save methane/a75ff64289f0aad7e3690d0c8884e9e7 to your computer and use it in GitHub Desktop.
$ cat x.py
import sys
import typing
for i in range(1000):
del sys.modules['typing']
import typing
$ time python3 x.py
real 0m11.392s
user 0m11.232s
sys 0m0.131s
# Importing typing module takes 11ms
$ python3 -m cProfile -stime x.py
8207297 function calls (8206201 primitive calls) in 9.639 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
106106 2.863 0.000 2.863 0.000 {built-in method __new__ of type object at 0x10e3f5650}
237237 1.327 0.000 1.327 0.000 _weakrefset.py:36(__init__)
79079 1.065 0.000 7.606 0.000 abc.py:132(__new__)
1830829 0.845 0.000 0.845 0.000 {built-in method builtins.getattr}
1001 0.793 0.001 0.793 0.001 {built-in method marshal.loads}
65065 0.600 0.000 7.751 0.000 {built-in method builtins.__build_class__}
2493498 0.493 0.000 0.493 0.000 {built-in method builtins.isinstance}
1482481 0.396 0.000 0.396 0.000 {method 'startswith' of 'str' objects}
79079 0.194 0.000 0.737 0.000 abc.py:136(<setcomp>)
534534 0.127 0.000 0.127 0.000 {method 'endswith' of 'str' objects}
104104 0.078 0.000 0.078 0.000 {built-in method builtins.hasattr}
88088 0.053 0.000 0.140 0.000 {built-in method builtins.any}
2002 0.046 0.000 0.046 0.000 {built-in method posix.getcwd}
89089 0.044 0.000 0.044 0.000 {method 'update' of 'dict' objects}
280280 0.043 0.000 0.043 0.000 {method 'add' of 'set' objects}
10010 0.041 0.000 0.081 0.000 functools.py:44(update_wrapper)
5005 0.038 0.000 0.040 0.000 functools.py:448(lru_cache)
3003 0.036 0.000 0.123 0.000 <frozen importlib._bootstrap_external>:1233(find_spec)
40040 0.034 0.000 0.071 0.000 {built-in method builtins.all}
1001 0.033 0.000 0.059 0.000 <frozen importlib._bootstrap_external>:830(get_data)
37037 0.032 0.000 0.041 0.000 {built-in method builtins.hash}
5005 0.032 0.000 0.032 0.000 {built-in method posix.stat}
145147 0.030 0.000 0.030 0.000 {method 'append' of 'list' objects}
1001 0.026 0.000 0.026 0.000 {method 'read' of '_io.FileIO' objects}
1001 0.020 0.000 0.024 0.000 <frozen importlib._bootstrap_external>:430(_validate_bytecode_header)
79080 0.018 0.000 0.018 0.000 {method 'items' of 'dict' objects}
99104 0.017 0.000 0.017 0.000 {built-in method builtins.len}
50050 0.016 0.000 0.016 0.000 {built-in method builtins.setattr}
16016 0.014 0.000 0.041 0.000 <frozen importlib._bootstrap_external>:57(_path_join)
16016 0.013 0.000 0.021 0.000 <frozen importlib._bootstrap_external>:59(<listcomp>)
1001 0.013 0.000 0.213 0.000 <frozen importlib._bootstrap>:861(_find_spec)
1001 0.011 0.000 0.915 0.001 <frozen importlib._bootstrap_external>:743(get_code)
27027 0.011 0.000 0.011 0.000 abc.py:9(abstractmethod)
2002 0.010 0.000 0.021 0.000 <frozen importlib._bootstrap_external>:263(cache_from_source)
1001 0.010 0.000 0.189 0.000 <frozen importlib._bootstrap_external>:1117(_get_spec)
5005 0.010 0.000 0.059 0.000 functools.py:479(decorating_function)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment