How to measure execution time of a program

Fredrik Lundh fredrik at pythonware.com
Wed Jun 28 03:58:29 EDT 2006


Girish Sahani wrote:

> Can anyone tell me the simplest way to do it (some code snippet that
> could be included in the program's main function) ??

simplest way:

    t0 = time.time()
    main()
    print time.time() - t0, "seconds"

(assuming that you want to measure wall time, and that your program runs
for at least a tenth of second, or so.  for benchmarking of short code snippets,
see the "timeit" module)

</F> 






More information about the Python-list mailing list