File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -21,14 +21,19 @@ pip install ultralytics-autoimport
2121Use the ` lazy ` context manager to defer imports:
2222
2323``` python
24+ import time
25+
2426from autoimport import lazy
2527
2628with 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
You can’t perform that action at this time.
0 commit comments