Created
February 28, 2025 15:34
-
-
Save vmoens/5c9fb9d1572ddb10b15d762b1dea3e49 to your computer and use it in GitHub Desktop.
import_speed
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 timeit | |
| # Create a simple module structure for demonstration purposes | |
| class Module: | |
| class Package: | |
| class Subpack: | |
| def func(self): | |
| pass | |
| module = Module() | |
| def test_long_chain(): | |
| module.Package.Subpack().func() | |
| from_module = module.Package.Subpack() | |
| def test_short_chain(): | |
| from_module.func() | |
| from_module_imp = module.Package.Subpack().func | |
| def test_imported_func(): | |
| from_module_imp() | |
| long_chain_time = timeit.timeit(test_long_chain, number=1000000) | |
| short_chain_time = timeit.timeit(test_short_chain, number=1000000) | |
| imported_func_time = timeit.timeit(test_imported_func, number=1000000) | |
| print(f"Long chain: {long_chain_time:.6f} seconds") | |
| print(f"Short chain: {short_chain_time:.6f} seconds") | |
| print(f"Imported func: {imported_func_time:.6f} seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment