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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -