time.time() on Linux seems to produce current time in us = 1/1000 ms precision.
Can I use that to profile functions in ms precision, by doing this:
func_start = time.time() * 1000
#run something inbetween
print 'Function finishes in: %.3f ms' % ((time.time() * 1000) - func_start)
No, you don’t increase the precision that way. You could just as well do:
but to measure performance of a function accurately, you really need to re-run it several times to remove the effects of OS scheduling, coinciding disk flush interrupts, etc.
For timing methods as accurately as your platform will allow, use the
timeitmodule, or at least re-use it’sdefault_timer()function.