Evaluating time

Fredrik Lundh fredrik at pythonware.com
Sat Dec 13 06:51:43 EST 2003


Angelo Secchi wrote:

> What is the best way to check how long a python script  takes to be
> executed ?

for simple cases, use

    import time

    t0 = time.time() # walltime
    ... code ...
    print time.time() - t0, "seconds"

or

    import time
    t0 = time.clock() # cpu time (*)
    ... code ...
    print time.clock() - t0, "seconds"

*) the exact definition of CPU time is platform dependent

for detailed benchmarking of small snippets in 2.3 and later,
use the timeit module:

    http://www.python.org/doc/current/lib/module-timeit.html

</F>








More information about the Python-list mailing list