6

for example:

In [5]: import time
In [6]: def test():
   ...:     t0=time.clock()
   ...:     import pandas as pd
   ...:     import numpy  as np
   ...:     import matplotlib.pyplot as plt
   ...:     t1=time.clock()
   ...:     print t1-t0
   ...:

In [7]: test()
10.8699593575

on my computer those statements consume over 10 second, so when debugging, it's little annoying to run python script using those module.

it's there is good way to solve it?

王王王
  • 127
  • 1
  • 10
  • You can use `%run` in the IPython shell to run your script. You don't need to restart IPython between runs, so the modules will remain loaded. (That said, it only takes 0.2 seconds in a fresh interpreter on my machine once the modules have been compiled to `.pyc` files and cached by the operating system. Maybe you are short on memory? Or using Windows?) – Sven Marnach Aug 04 '16 at 13:14
  • yes, it's ok! i can use those modules happily again !!! – 王王王 Aug 05 '16 at 00:55

1 Answers1

3

try line profiler to determine which package takes more time:

enter image description here

Also you may import only the function you need to reduce the time/memory.

enter image description here

Ayman
  • 51
  • 5
  • 3
    Good stuff, but screen shots of textual information are a plague. Could you at least summarize the results as indexable, screen-readerable, font-resizable text? – tripleee Jan 08 '20 at 06:23
  • 3
    Using the syntax `from import ` is NOT faster, see https://stackoverflow.com/a/710603/2135504 You probably get different results because the library has already been imported the second time you call it. – gebbissimo Nov 30 '21 at 13:50