formatting time as milliseconds in logging module
jcarlson at uci.edu
Tue Oct 19 18:47:30 CEST 2004
> The logging module nicely prepends each line with a formatted date.
> However, I'm not interested in the actual date but only in the number of
> milliseconds that passed since the start of the program. What is the best
> way of doing that?
In Windows: time.clock() will get you the number of seconds since you
last called it, down to the microsecond (trim as you see fit).
In linux, time.clock() gives you the amount of processor time used, so
it is not quite as useful in this case.
In both, time.time() will give you the number of seconds since the epoch,
so you can call it once when the program starts, and later just
subtract the times. In Windows, it is only accurate to .01 seconds, and
I don't know how accurate the linux version is (I expect about as
accurate, but I can certainly be wrong).
More information about the Python-list