Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

forever loops and cpu usage

 [1/15] from: ptretter:charter at: 7-Feb-2004 14:53


What are some ways to minimize cpu usage in forever loops? such as: forever [time: do now/time] Alot of scripts I make that use Forever loops end up eating the cpu. Paul Tretter

 [2/15] from: maarten:vrijheid at: 7-Feb-2004 23:10


Paul Tretter wrote:
>What are some ways to minimize cpu usage in forever loops? >such as:
<<quoted lines omitted: 5>>
>Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.577 / Virus Database: 366 - Release Date: 2/3/2004
add a wait 0.002 or more. --Maarten

 [3/15] from: tomc:darkwing:uoregon at: 7-Feb-2004 15:29


forever [time: do now/time wait 1] On Sat, 7 Feb 2004, Paul Tretter wrote:

 [4/15] from: ptretter:charter at: 7-Feb-2004 17:45


Yeah I actually have that now in a forever loop. I was just wondering if there were other ways to do it. However, that is a good tip for those experiencing the same issue that might be new to REBOL. Thanks. Paul Tretter

 [5/15] from: ptretter:charter at: 7-Feb-2004 17:45


Seems to be a consensus developing. Is this how other languages handle this issue also? Paul Tretter

 [6/15] from: maarten:vrijheid at: 8-Feb-2004 8:49


In a multitasking environment, you take what you can get. So a forever loop tries to eat up the cpu. Inserting a wait 0.002 (I found the number by experiment on Win/Lin two years ago) behaviour is normal. Especially when doing: some-port-list forever [ wait/all compose [ (some-port-list) 0] ..... ] when I changed the 0 to 0.002 I had a high-performance, non-blocking IO-engine that turned into RUgby a few months later. And didn't ate the CPU..... --Maarten Paul Tretter wrote:

 [7/15] from: gchiu:compkarori at: 8-Feb-2004 9:30


Maarten Koopmans wrote.. apparently on 8-Feb-2004/8:49:54+1:00
>In a multitasking environment, you take what you can get. So a forever >loop tries to eat up the cpu. >Inserting a wait 0.002 (I found the number by experiment on Win/Lin two >years ago) behaviour is normal.
Good to know. I'm using wait 0.2 for REBOLml when reindexing and it allows other tasks to work well. But I should try this value as well... -- Graham Chiu http://www.compkarori.com/cerebrus

 [8/15] from: maarten:vrijheid at: 8-Feb-2004 11:13


What I found (two years ago) was 2-3 ms. Of course, things may have changed, both REBOL- and OS-wise. So let me know if you find different results. --Maarten Graham Chiu wrote:

 [9/15] from: ptretter:charter at: 8-Feb-2004 9:07


On WinXP here I can get as precise as .001 on the wait time. However, it appears that anything less than that storms the cpu back up to 99 percent. I suppose that .001 is the lowest number that the wait function can support. I'm curious why you arrived at .002. Was it the balance point for windows and linux. I would like others to report on what OS they use and report their findings. HOW LOW CAN YOU GO? dec: .001 forever [a: do now/time dec] Please let me know what OS you use and how low your dec number can be set at before your cpu usage goes up. Paul Tretter

 [10/15] from: maarten:vrijheid at: 8-Feb-2004 17:34


This (0.002) was tested on Win2000 and Linux 2.4.x --Maarten Paul Tretter wrote:

 [11/15] from: greggirwin::mindspring::com at: 8-Feb-2004 11:25


Hi Paul, PT> Seems to be a consensus developing. Is this how other languages handle this PT> issue also? Basically, yes. That is, this is a basic scenario. If you're writing some kind of event-driven system (e.g. a GUI framework), sometimes there are more complex interactions. For example, under Windows calling certain APIs (GetMessage, PeekMessage) yield to the system in specific ways to keep a task from eating the CPU. Even deeper, there is just a big message pump running, so you see the System Idle process using all the CPU time if nothing else is going on. -- Gregg

 [12/15] from: the:optimizer:tiscali:it at: 8-Feb-2004 20:28


> Seems to be a consensus developing. Is this how other languages handle > this > issue also?
I think the best answer can come from one of the best programmer, who once dealt with those things and solved those problem in a way still unsurpassed. And, by coincidence, he's also the author of Rebol. M&F

 [13/15] from: lmecir:mbox:vol:cz at: 8-Feb-2004 21:59


Paul Tretter napsal(a):
>On WinXP here I can get as precise as .001 on the wait time. However, it >appears that anything less than that storms the cpu back up to 99 percent. >I suppose that .001 is the lowest number that the wait function can support. >I'm curious why you arrived at .002. Was it the balance point for windows >and linux. I would like others to report on what OS they use and report >their findings. HOW LOW CAN YOU GO? >
I have got a timing function working as follows: tick-time: time-tick 0.1 ; == 1.00000000002183E-2 , which computes the internal system timer resolution, 0.1 is an argument asking for 10% relative error at most. Other results:
>> time-block [wait 0.02] 0,05
== 2.00312500001019E-2
>> time-block [wait 0.01] 0,05
== 1.00156250000509E-2
>> time-block [wait 0.005] 0,05
== 1.00156250000509E-2
>> time-block [wait 0.002] 0,05
== 1.00156249998236E-2
>> time-block [wait 0.001] 0,05
== 1.00117187499791E-2 look like showing, that all below the system timer resolution are rounded up to the system timer. OTOH, times below 0.001 exhibit this:
>> time-block [wait 0.00099] 0,05
== 4.85229492186434E-6 -L

 [14/15] from: ptretter:charter at: 8-Feb-2004 16:53


That's very interesting. With your functions are you able to determine the optimum performance wait time? And if so, is it platform independent? This information is really necessary to get published if people are making platform independent scripts. Paul Tretter

 [15/15] from: Izkata:comcast at: 8-Feb-2004 19:59


> On WinXP here I can get as precise as .001 on the wait time. However, it > appears that anything less than that storms the cpu back up to 99 percent. > I suppose that .001 is the lowest number that the wait function can
support.
> I'm curious why you arrived at .002. Was it the balance point for windows > and linux. I would like others to report on what OS they use and report > their findings. HOW LOW CAN YOU GO? > > dec: .001 > > forever [a: do now/time dec] > > Please let me know what OS you use and how low your dec number can be set
at
> before your cpu usage goes up.
Win XP results (For Me)---> Actually, I got it up to 12.00 before I gave up lol..... Apparently, over here, *any* Forever loop eats up CPU Usage...

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted