Easiest way to calculate python script runtime?

What is the easiest way to calculate Python script runtime?

+4
source share
4 answers

The timeit module is designed specifically for this purpose.

Silly example as follows

def test(): """Stupid test function""" L = [] for i in range(100): L.append(i) if __name__ == '__main__': from timeit import Timer t = Timer("test()", "from __main__ import test") print t.timeit() 

Note that timeit can also be used from the command line (python -m timeit -s 'module' 'module.test ()') and that you can run several times to get a more accurate measurement. Something. I think the time command does not support directly. - jcollado

+8
source

Using the Linux time command, do the following: time python file.py

Or you can take the time at the beginning and at the end and calculate the difference.

+4
source

Under linux: python script.py

+1
source

How about using time ?
example: time myPython.py

0
source

Source: https://habr.com/ru/post/1387963/


All Articles