Created
November 12, 2019 19:05
-
-
Save mdboom/52194b2fbafb5548f1cde9d9965c8344 to your computer and use it in GitHub Desktop.
Measures the amount of code loaded by "import X"
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 os | |
import sys | |
original_modules = dict(sys.modules) | |
import pandas | |
sizes = {} | |
total = 0 | |
files = set() | |
for name, module in sys.modules.items(): | |
if name in original_modules: | |
continue | |
if hasattr(module, "__file__"): | |
filename = module.__file__ | |
files.add(filename) | |
for filename in files: | |
stat = os.stat(filename) | |
total += stat.st_size | |
for package in ["pandas", "numpy", "matplotlib", "dateutil"]: | |
if f"site-packages/{package}/" in filename: | |
sizes.setdefault(package, 0) | |
sizes[package] += stat.st_size | |
break | |
else: | |
sizes.setdefault("stdlib", 0) | |
sizes["stdlib"] += stat.st_size | |
print(total) | |
print(sizes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment