Jan-21-2020, 06:58 PM
Hi!
I have a very fast desktop running Windows 10 and Python 3.7.5 (also checked with 3.81 and on other computers and fast laptops).
I used time.sleep() function to control speed in an animation and I noticed weird behavior: precision of the delay is not great and it heavily depends on what other programs are doing on the computer. The most impressive difference is when Chrome is running an animation (e.g. animated GIF or any video from Youtube). Contrary to what you would expect, running Chrome+Youtube reduces overhead of time.sleep() function call.
Test program.
Python, alone on the computer
0.0 0.0
0.0001 10.005327463150024
0.001 10.00532841682434
0.002 10.005328178405762
0.005 10.005327463150024
0.01 11.115919351577759
0.1 100.30341053009033
Python, Chrome + Youtube running
0.0 0.0004968643188476562
0.0001 1.193671464920044
0.001 1.1876120567321777
0.002 2.1876208782196045
0.005 5.2599778175354
0.01 10.306353569030762
0.1 100.33435225486755
To take a stone of the chest of Python developers, this is not (only) a bug in Python but it is a problem somewhere where Python relies on Microsoft OS. Namely, below are results of a similar program in C compiled with cygwin:
Cygwin C, Chrome + Youtube ON
0 0.000674
0.0001 0.629586
0.001 1.335396
0.002 2.282565
0.005 5.288572
0.01 10.31289
0.1 100.3234
Cygwin C, alone on the computer
0 0.000658
0.0001 9.99681
0.001 10.00531
0.002 10.00528
0.005 10.00526
0.01 14.72778
0.1 100.4138
Is there a way for me as user, or Python developers to improve on this?
Thanks.
I have a very fast desktop running Windows 10 and Python 3.7.5 (also checked with 3.81 and on other computers and fast laptops).
I used time.sleep() function to control speed in an animation and I noticed weird behavior: precision of the delay is not great and it heavily depends on what other programs are doing on the computer. The most impressive difference is when Chrome is running an animation (e.g. animated GIF or any video from Youtube). Contrary to what you would expect, running Chrome+Youtube reduces overhead of time.sleep() function call.
Test program.
import time dly=[0.0, 0.0001, 0.001, 0.002, 0.005, 0.01, 0.1] for j in range(7): t0=time.time() for i in range (1000): time.sleep(dly[j]) t1=time.time() print(dly[j], t1-t0)Results.
Python, alone on the computer
0.0 0.0
0.0001 10.005327463150024
0.001 10.00532841682434
0.002 10.005328178405762
0.005 10.005327463150024
0.01 11.115919351577759
0.1 100.30341053009033
Python, Chrome + Youtube running
0.0 0.0004968643188476562
0.0001 1.193671464920044
0.001 1.1876120567321777
0.002 2.1876208782196045
0.005 5.2599778175354
0.01 10.306353569030762
0.1 100.33435225486755
To take a stone of the chest of Python developers, this is not (only) a bug in Python but it is a problem somewhere where Python relies on Microsoft OS. Namely, below are results of a similar program in C compiled with cygwin:
Cygwin C, Chrome + Youtube ON
0 0.000674
0.0001 0.629586
0.001 1.335396
0.002 2.282565
0.005 5.288572
0.01 10.31289
0.1 100.3234
Cygwin C, alone on the computer
0 0.000658
0.0001 9.99681
0.001 10.00531
0.002 10.00528
0.005 10.00526
0.01 14.72778
0.1 100.4138
Is there a way for me as user, or Python developers to improve on this?
Thanks.