[Tutor] stable algorithm

spir denis.spir at free.fr
Sun Dec 14 19:32:34 CET 2008


David Hláčik a écrit :
> Hi,
> 
> thank you very much.
> 
> And how can i write single test which will tell me execution time of
> this algorithm?
> 
> I need to write a table with number of data & execution time
> comparison (and it should be linear in case of this algorithm)
> 
> Thanks!
> 
> D.
> 
First, google will give you tons of links on the topic.
time.time() returns present time in ms
The func below is practicle, too.
denis

	
def timer(n,f,*args,**kw_args):
	t0 = time()
	for i in range(n):
		f(*args,**kw_args)
	t = time() - t0
	arg_str = ','.join(str(arg) for arg in args)
	kw_arg_str = ','+str(kw_args)[1:-1] if kw_args else ''
	print "%s(%s%s) %s time(s) <--> %0.3f s" % (f.__name__,arg_str,kw_arg_str,n,t)



More information about the Tutor mailing list