[Pyrex] Re: any ideas to speed this up?

John Machin sjmachin at lexicon.net
Thu Feb 23 10:39:31 CET 2006


On 23/02/2006 8:23 PM, Toby wrote:
> Brian Blais wrote:
> 
>>t1=time.time()
>>...
>>print time.time()-t1
> 
> 
> You might want to use time.clock() for benchmarking algorithms.  
> 
> time.time() measures the current (wall clock) time, so the difference
> you print includes any time spent by the CPU on other processes, or
> waiting for I/O, or responding to other computers on the network.
> 
> Instead time.clock() only measures the time spent by the CPU executing
> your user code, discarding anything else.  There's a catch: on most
> platforms time.clock() has a worse resolution (on my Linux pc it's .01s)
> So if you need to time algorithms that take much less than a second, you
> will have to repeat them a number of times, like this:
> 
> 	t = time.clock()
> 	for i in range(1000):
> 	    # stuff <<1s to measure goes here
> 	print (time.clock() - t) / 1000

The timeit module is your friend, unless you think you can write better 
code than the timbot :-)



More information about the Pyrex mailing list