Skip to content

Commit 89629cc

Browse files
Update README.md (#16)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
1 parent 299922e commit 89629cc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ pip install ultralytics-autoimport
2121
Use the `lazy` context manager to defer imports:
2222

2323
```python
24+
import time
25+
2426
from autoimport import lazy
2527

2628
with lazy():
27-
import torch # torch is only imported when used
29+
t0 = time.perf_counter()
30+
import torch # Import is deferred until first use
31+
32+
print(f"Initial import time: {time.perf_counter() - t0:.3f}s") # Example output: 0.000s
2833

29-
print("Torch imported:", "torch" in globals())
30-
torch.cuda.is_available() # Now torch is imported
31-
print("Torch imported:", "torch" in globals())
34+
t1 = time.perf_counter()
35+
torch.cuda.is_available() # Package is actually loaded here
36+
print(f"First use time: {time.perf_counter() - t1:.3f}s") # Example output: 0.462s
3237
```
3338

3439
## 🗂 Repository Structure

0 commit comments

Comments
 (0)