iteration - Does python iterate at a constant speed? -
i writing code sensor readings gpio against time. make sure measurements corresponds specific time, want know if python iterates @ constant speed (so gap between iterations constant) - , minimum time gap between iterations.
if they're not, can let me know how make time gap constant. thank you!
no, python not , can not iterate @ constant speed.
python process on raspberry pi, , os responsible allocating time run on cpu (called multi-tasking). other processes allotted time. means python never going running time , processing times going depend on other processes doing.
iteration delegated specific types; how next item produced varies widely, , if python given constant access cpu iteration still vary. whatever in loop body takes time, , unless inputs , outputs same, take variable amount of time work.
instead of trying time loops, measure time time.time()
or timeit.default_timer
(depending on how precise need be, on raspberry it'll same function) in loop , adjust actions based on that.
Comments
Post a Comment