Determining how long a script takes

The timeit function in Python takes a line of code and determines how long it takes to execute. You can also repeatedly execute the same script to see if there are start-up issues that need to be addressed.

timeit is used in this manner:

import timeit
t = timeit.Timer("myfunction('Hello World')", "import myfunction")   
t.timeit()              
3.32132323232
t.repeat(2, 2000000)    
[#, #, #]  

The repeat() function is telling timeit to execute the timed instruction two times at 2,000,000 times each. The numbers displayed after the repeat() call are the three of the times taken as representative of the repeated calls.

You would normally use this to test out a complete function, not something that interacts with the user in any way.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.212.102