Article #1068
Subject: command_utils:suspend and speed? (was Re: find?)
Author: Mark A. O'Neil
Posted: 3/10/2001 05:54:19 AM
--- Cipriano Groenendal wrote: for p in (players()) if (p.real_name == usr_name); return p; endif $command_utils:suspend_if_needed(0); endfor return #-1; would probably work best if you're gonna use a seperate verb:) --- How is "$command_utils:suspend_if_needed(0);" better than break? --- Cipriano Groenendal wrote: > ...if you make it result = {@result, {p, p.real_name}} ... You'd have to go use $list_utils:assoc() on this one afterwards tough:) --- end of quote --- Dealing with lists can be messy yes. Out of curiosity, anyone know the overhead for doing a "$list_utils:assoc()", on say a list of 1000, vs a "rName = p.real_name"? After some consideration, I would guess that the later is faster.... it is the gathering of the players for the list in the first place that was time consuming though it could be useful. Thanks! -m
Article #1070
Subject: Re: command_utils:suspend and speed? (was Re: find?)
Author: Kai van Poppel
Posted: 3/10/2001 06:40:25 AM
> --- Cipriano Groenendal wrote: > for p in (players()) > if (p.real_name == usr_name); > return p; > endif > $command_utils:suspend_if_needed(0); > endfor > return #-1; > > would probably work best if you're gonna use a seperate verb:) > --- > > How is "$command_utils:suspend_if_needed(0);" better than break? $command_utils:suspend_if_needed is not the same as "break"! When you're running out of ticks/seconds, you will have to suspend the verb to get new ticks and seconds. This security prevents the system from getting instable. You can also use something like this instead of the suspend_if_needed line: "ticks_left() < 4000 || seconds_left() < 2 && suspend(0);" (Even better) - Kai
Article #1071
Subject: Re: command_utils:suspend and speed? (was Re: find?)
Author: Mark A. O'Neil
Posted: 3/10/2001 10:16:47 AM
--- Kai van Poppel wrote: $command_utils:suspend_if_needed is not the same as "break"! When you're running out of ticks/seconds, you will have to suspend the verb to get new ticks and seconds. This security prevents the system from getting instable. You can also use something like this instead of the suspend_if_needed line: "ticks_left() < 4000 || seconds_left() < 2 && suspend(0);" (Even better) - Kai Okay so essentially $command_utils:suspend_if_needed suspends the verb so the server may attend to other tasks, after completing those tasks the server then reenters the verb. correct? I would still use break to kill the loop. correct? --- Kai van Poppel wrote: "ticks_left() < 4000 || seconds_left() < 2 && suspend(0);" (Even better) --- end of quote --- This would appear to do roughly the same as $command_utils:suspend_if_needed. Better because? Higher level of control? -m
Article #1072
Subject: Re: command_utils:suspend and speed? (was Re: find?)
Author: Matthew Kerwin
Posted: 3/10/2001 11:10:58 AM
>From: "Mark A. O'Neil" <Mark.A.O'Neil@nospam> > >I would still use break to kill the loop. correct? No, the `return' line does it better. The method given as an example was a different verb. If you were to include it as a snippet inside your other verb, then yes, 'break p;' would probably come in kinda handy in place of return. mAtTY _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com
Article #1073
Subject: Re: command_utils:suspend and speed? (was Re: find?)
Author: Chris Jones
Posted: 3/10/2001 01:23:16 PM
On Sat, 10 Mar 2001, Mark A. O'Neil wrote: > --- Kai van Poppel wrote: > "ticks_left() < 4000 || seconds_left() < 2 && suspend(0);" (Even better) > --- end of quote --- > > This would appear to do roughly the same as $command_utils:suspend_if_needed. > Better because? Higher level of control? If you read $command_utils:s_i_n, you'll see that that's the operative line of it; everything else if more or less useless overhead at this point. Just inlining the ticks_left() ... suspend() statement means that you don't have that overhead nor the verb-call overhead. Really, unless you're an efficiency freak (in which case you shouldn't be using MOO at all) or unless you have very specialized needs, it doesn't make a difference whether you use s_i_n or the inlined version.
Article #1074
Subject: Re: command_utils:suspend and speed? (was Re: find?)
Author: Cipriano Groenendal
Posted: 3/10/2001 02:28:16 PM
>> --- Cipriano Groenendal wrote: >> for p in (players()) >> if (p.real_name == usr_name); >> return p; >> endif >> $command_utils:suspend_if_needed(0); >> endfor >> return #-1; >> >> would probably work best if you're gonna use a seperate verb:) > How is "$command_utils:suspend_if_needed(0);" better than break? This piece of code was meant as a seperate verb. The suspend is there incase you have a huge amount of players to check. As you can see, as soon as it finds a match the verb returns, thus ending this current verb and skipping the rest of the loops:) >> > ...if you make it result = {@result, {p, p.real_name}} ... >> >> You'd have to go use $list_utils:assoc() on this one afterwards tough:) > Dealing with lists can be messy yes. Out of curiosity, anyone know the overhead for doing a "$list_utils:assoc()", on say a list of 1000, vs a "rName = p.real_name"? > After some consideration, I would guess that the later is faster.... it is the gathering of the players for the list in the first place that was time consuming though it could be useful. The second is definately faster, yes. Simply because it won't gather all thousand names first, but will stop as soona s it finds the name. -- || Cipriano Groenendal |\______________________________ ___ | ______________________________| sig |___| |/ || MAIL: cipri@nospam || WWW: http://www.cipri.com || MOO: telnet://moo.NowMOO.nl:2001 || ICQ: #5820598 AIM: Cieper || GF: http://www.Cerala.com/ |\______________________________ ___ \_______________________________| eof |___|
Article #1075
Subject: Re: command_utils:suspend and speed? (was Re: find?)
Author: Mark O'Neil
Posted: 3/10/2001 05:08:04 PM
on 3/10/01 12:10 PM, Matthew Kerwin at phluid_61@nospam wrote: >> I would still use break to kill the loop. correct? > > No, the `return' line does it better. The method given as an example was a > different verb. If you were to include it as a snippet inside your other > verb, then yes, 'break p;' would probably come in kinda handy in place of > return. > > mAtTY Right, it all depends on what happens next and if it is a snippet inside another verb which I was not very clear about. In this case it is a snippet and I need to break the loop and carry onward when I find a match. The $command_utils:suspend_if_needed bit is good to include, I suppose, given the possibility of a huge number of players. Thanks, -m