Created
March 3, 2024 11:29
-
-
Save antonagestam/86f96f3dccee8c8ff7711f9647c5783a to your computer and use it in GitHub Desktop.
Eagerly load all kio modules, takes 2-3s
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 kio.schema | |
from pkgutil import iter_modules | |
from pkgutil import resolve_name | |
import time | |
from pathlib import Path | |
schema_dir = Path(kio.schema.__file__).parent.resolve() | |
print(f"{schema_dir=}") | |
t0 = time.monotonic_ns() | |
for api_mod in iter_modules([schema_dir]): | |
api_dir = schema_dir / api_mod.name | |
for version_mod in iter_modules([api_dir]): | |
version_dir = api_dir / version_mod.name | |
for type_mod in iter_modules([version_dir], prefix=f"kio.schema.{api_mod.name}.{version_mod.name}."): | |
imported = resolve_name(type_mod.name) | |
# print(f"{imported=}") | |
t1 = time.monotonic_ns() | |
d = (t1 - t0) / 1_000_000 | |
print(f"took {d:.2f}ms") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment