python - time.clock() doesn't return time properly -
this code:
import time = time.clock() while + 5 > time.clock(): print time.clock() time.sleep(1) print "woke up"
returns:
0.015718 woke 0.015814 woke 0.015942 woke 0.016107 woke 0.01625 woke 0.016363
as can see, time returned not seem return elapsed time seconds represented integers, though documentation says should do. wrong here?
edit: i'm on mac os x el capitan
you should read manual:
on unix, return current processor time floating point number expressed in seconds. precision, , in fact definition of meaning of “processor time”, depends on of c function of same name, in case, function use benchmarking python or timing algorithms. on windows, function returns wall-clock seconds elapsed since first call function, floating point number, based on win32 function queryperformancecounter(). resolution typically better 1 microsecond.
that assuming you're using unix (fx linux or ios) behaviour correct. time.clock
returns amount of cpu time process has consumed, when sleeping don't consume cpu time.
of course difference between unix , windows makes function useless unless detect behavior in effect , act accordingly.
Comments
Post a Comment