![](templates/Classic/images/spacer.gif) |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Tue Nov 13, 2007 6:44 am
Alarms vs Loops |
Which is faster? Is it faster to use alarms to repeat an action every two seconds or to use while or until loops with a #wait and #abort?
I'm trying to figure out how to streamline my code to be the fastest possible. One reason is I have a pretty sorry connection to the MUD to begin with so blazing fast speed is always a plus for me when processing scripts. |
|
|
![](templates/Classic/images/spacer.gif) |
Fang Xianfu GURU
![](images/avatars/1763170544a2093e7e85da.gif)
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Nov 13, 2007 11:24 am |
Shouldn't make a difference, but the simplest answer is Try It And See. There are too many things at work here (depending on the kind of scripts you're running, what other stuff is happening, and so on). Use the script debugger to see how long each option takes.
|
|
|
![](templates/Classic/images/spacer.gif) |
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Tue Nov 13, 2007 12:21 pm |
Feel free to post results of your testing here too.
|
|
|
![](templates/Classic/images/spacer.gif) |
Zugg MASTER
![](images/avatars/164475849040f41c23b22fe.gif)
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Nov 13, 2007 5:33 pm |
My guess is that in v2 using a Loop will probably be faster. The #wait uses the Windows WaitForMultipleObjects API routine, which is very efficient. And when it wakes up, the thread is already primed and ready to continue, so there isn't any additional overhead. With an alarm, it uses a Windows Timer object, which takes Windows resources, and when the timer expires, it has to wait until Windows processes the WM_TIMER event, so the alarm might not start at exactly the right time if something else is busy. Then, once the WM_TIMER event is processed, CMUD creates a new thread for the alarm and runs it, so you have the overhead of creating a thread. Alarms do not re-use threads, so when the alarm finishes, it also destroys it's current thread. So alarms have more overhead.
But if you get some interesting results, I'd love to see the actual timings too. |
|
|
![](templates/Classic/images/spacer.gif) |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Wed Nov 14, 2007 5:59 am |
Well when I changed all the alarms to #until loops it would barely work and then CMUD just crashed.
This is just using the example such as:
Alias EatHerb:
Code: |
HerbEaten=0
#UNTIL (@HerbEaten) {
#send {eat herb}
#wait 2000
}
|
I did the same with salves, elixirs and so on instead of the alarms. Using the alarms it works fine. I hate this multithreading stuff. [/code] |
|
|
![](templates/Classic/images/spacer.gif) |
Zugg MASTER
![](images/avatars/164475849040f41c23b22fe.gif)
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Nov 14, 2007 5:31 pm |
I just tried your example above and it worked fine for me here. It sent "eat herb" every 2 seconds until I entered "HerbEaten=1" on the command line. So, I'm not sure what the problem is, but my guess is that it is interacting with something else in your scripts.
|
|
|
![](templates/Classic/images/spacer.gif) |
Tech GURU
![](images/avatars/172896370346230b24779a1.gif)
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Wed Nov 14, 2007 6:49 pm |
I think is concern was if he puts that code in an alias and it gets called 5 times. See this thread for more info.
[Edit] Silent Ninja. You posted to the linked thread while I was posting this. ![Smile](images/smiles/icon_smile.gif) |
|
_________________ Asati di tempari! |
|
|
![](templates/Classic/images/spacer.gif) |
|
|