[Tutor] Time - Less then a second

exnihilo at myrealbox.com exnihilo at myrealbox.com
Thu Jan 8 22:02:12 EST 2004

Isr Gish wrote:
> I'm looking to be able to get time in less then seconds.
> I have looked in the time module and seen the time.clock() and time.time() functions. But on my machine (Pocket PC running Python Ver. 2.3.2) it doesn't return anything less than seconds. And they both return the same thing, (the full time since ??? In seconds).
> If someone can please point me in the right direction it would be greatly appreciated.
> (I have used ticks() previously in PocketC for the Windows CE platform. I have never programmed in any other language before besides PocketC) 
> ---------------
> Isr Gish

hi Isr,

The following little snippet illustrates how time.clock() works. I've 
never used time.time() before though.

 >>> import random, time
 >>> def timeSort(l):
	start = time.clock()
	print "Sort Time:", (time.clock() - start) * 1000, "milliseconds"

 >>> randList = [random.random() for i in range(100000)]
 >>> timeSort(randList)
Sort Time: 190.0 milliseconds
 >>> # you don't want to print that huge

time.clock() returns a time in seconds as a floating point number (see 
help(time.clock)) to as much precision as the system provides, so I 
think that should satisfy your requirement (if you want milliseconds, 
just multiply by 1000 as I did in the example).

Hope that helps...

More information about the Tutor mailing list