|
NitroGlycerine Beginner
Joined: 26 Apr 2007 Posts: 29
|
Posted: Tue Feb 03, 2009 11:50 pm
trigger speed diagnostics? |
Is there any form of trigger speed diagnostics included in CMUD? Like total amount of triggers, total amount of time lost checking all triggers, measuring the speed of certain scripts, ...?
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Feb 04, 2009 2:12 am |
Press Ctrl+Q a whole bunch of times so it fills the buffer, then press it again. This basically prints a bunch of garbage lines, which all your triggers then have to be tested against. But this only measures the time taken for a trigger to fail matching - which is fine, since most lines won't match most triggers. But if you have a trigger, like a prompt, that fires all the time, its time to a correct match might be more important than its time to failure, which is something only you can test.
Measuring the speed of scripts is a difficult prospect, because it depends not only on how fast the script actually is, but how often it runs and what else is going on at the same time. You can broadly measure the speed of some code by #looping it a bunch of times so that it's long enough to be measured, and then comparing the value of %secs before and after you ran the script. Then you can compare that script with some different versions that may or may not be faster, and see which is the best alternative.
Unfortunately, the only real way for you to diagnose if something's being slow during normal operation is to just watch what scripts are running in the debugger. If something is running too often or for too long, it needs changing. |
|
|
|
NitroGlycerine Beginner
Joined: 26 Apr 2007 Posts: 29
|
Posted: Wed Feb 04, 2009 9:33 am |
Oh great thanks, are there any general guidelines about trigger speed? Are regex triggers faster at matching for example?
|
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Wed Feb 04, 2009 11:53 am |
Well ZMud style patterns are converted to regex internally. You can see the exact pattern used in the testing tab for that trigger. So as long as the regex you were going to write is the same as the regex that the ZMud style pattern was converted to, they should be exactly the same speed. In some cases, though, ZMud-style patterns just don't give you as much control, so you can achieve some optimization IF you know what you're doing with regex. I understand that the O'Reilly book Mastering Regular Expressions has a whole chapter devoted to optimization, it's supposed to be really good...you might be able to find it at your local library. There's also a lot information floating around on the web, obviously, but it can be hard to find.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Feb 04, 2009 4:14 pm |
There are a number of tips on increasing the speed of your code, but each such tip only helps a tiny bit. Added together, they can make a difference. Here are a few tips off the top of my head.
Whenever possible, use local variables instead of nonlocal variables ($myvar instead of @myvar). Local variables are much faster.
If you have to use a nonlocal variable but don't need to keep the value between sessions, set the variable to Use Default. That way it doesn't have to store the value to disk.
Enabling and Disabling something is much faster than creating and destroying it repeatedly. Even enabling and renaming it is faster.
If you have huge numbers of triggers which are only needed under certain situations, it may be effective to disable most of them except when conditions arise under which they might be expected to fire.
I should also point out that unless you have a huge volume of code, a slow computer, or are doing something very odd, execution speed is generally not a problem on cmud. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Feb 04, 2009 7:36 pm |
As a corollary to Rahab's second tip, you rarely actually need to store data across sessions - think carefully about it. Most stuff can be captured again just by entering a command, like SCORE to list your stats or SKILLS to show your skills.
|
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Thu Feb 05, 2009 12:08 pm |
Oh, also use #print instead of #echo, etc., to echo things to the screen when you don't need triggers to match on the echoed line (it doesn't even try to match triggers, which is obviously faster).
|
|
|
|
|
|