Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: 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.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Tue Nov 13, 2007 12:21 pm   
 
Feel free to post results of your testing here too.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: 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]
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: 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
_________________
Asati di tempari!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net