From 89629cc56b44f3b0dedf5d91a9d309d40c9f927e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 16 Jan 2025 18:00:47 +0100 Subject: [PATCH] Update README.md (#16) Signed-off-by: Glenn Jocher Co-authored-by: UltralyticsAssistant --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 649eedf..ee66f36 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,19 @@ pip install ultralytics-autoimport Use the `lazy` context manager to defer imports: ```python +import time + from autoimport import lazy with lazy(): - import torch # torch is only imported when used + t0 = time.perf_counter() + import torch # Import is deferred until first use + + print(f"Initial import time: {time.perf_counter() - t0:.3f}s") # Example output: 0.000s - print("Torch imported:", "torch" in globals()) - torch.cuda.is_available() # Now torch is imported - print("Torch imported:", "torch" in globals()) +t1 = time.perf_counter() +torch.cuda.is_available() # Package is actually loaded here +print(f"First use time: {time.perf_counter() - t1:.3f}s") # Example output: 0.462s ``` ## 🗂 Repository Structure