execution time

Andreas Kostyrka andreas at kostyrka.org
Sun Dec 14 12:35:24 EST 2008


On Sun, Dec 14, 2008 at 05:03:38PM +0100, David Hláčik wrote:
> Hi guys,
> 
> #! /usr/bin/python
> 
> import random
> import bucket2
> 
> data = [ random.randint(1,25) for i in range(5)]
> print "random data : %s" % data
> print "result: %s" %bucket2.sort(data)
> 
> How to write a test script which will outputs execution time for
> bucket2.sort(data) ?

Well:

import time

starttime = time.time()

....

endtime = time.time()
print "Whatever .... does, it took %5.3fs to do." % (endtime - starttime)

Alternativly take a look at the timeit standard module.

Andreas

> 
> Thanks in advance!
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list