From: Jonathan B. <jbr...@ea...> - 2004-05-13 01:48:52
|
On Wed, 2004-05-12 at 21:04, Jaap Spies wrote: > Bruce Sherwood wrote: > >> Hmm, Stonehenge takes ~20% of the cpu on my XP laptop. The date at the > >> top of __init__.py is "Visual-2003-10-05". Perhaps I will try a more > >> recent release. > >> > >> If that renderer thread doesn't sleep at some point in its loop, it will > >> consume a lot of CPU just looping, but usually that behavior is to use > >> 100% of the CPU. Actually the renderer thread isn't running in a traditional for() or while() loop. It is being periodically called as a callback from a GUI event loop - either Win32 on MS Windows, or gtk_main() on Linux and OSX. > With the same Visual-2003-10-05 I get 99% CPU for pythonw.exe executing bounce2.py > on my 2.7 GHz XP laptop. The OS[1] will not reliably allow you to sleep for a time slice smaller than 10 ms, so when the rate() function sees that you have less than 10 ms remaining before the rate() statement is to expire, it times it by busy wait - it runs in a tight loop until the OS reports that the remaining time is up. Remember that the rate function attempts to ensure that you execute the loop it is in at the requested rate - it is not a simple wait function. So, if you request a loop time of 10ms (such as the inner loop of bounce2.py), your code will take up some of that time to run the loop and the rate statement is forced to consume the rest by running in its own loop rather than a sleep system call. If you reduce the rate to (say) 90 you will see the amount of CPU consumed drops considerably. For reference, it only consumes about 3% CPU on my aging 800 MHz PIII when I do this. > Starting an other session they share the CPU cycles 50% resp. 49%. If you also look closely, you will see that the two running side-by-side should have bouncing balls that move about as fast as one running alone. This is in spite of appearing to be halving the amount of processing power available to each. HTH, Jonathan Brandmeyer [1]. OK, technically, some OS's will allow you to wait for smaller increments, and Linux will allow it in 1 ms increments if you are root, but real-time operating systems aren't exactly the target platform for VPython, and I wouldn't run VPython as root on my system even knowing what it is doing! ;) |