Posted by
| Nick Gammon
Australia (23,100 posts) Bio
Forum Administrator |
Message
| This is an interesting question. It is hard to say for sure on things like whether or not the trigger has a ^ a the start - although you could test it like I have done below.
My first point is that if there is something that is much more likely to match than other things (eg. the prompt line) then it will be quicker to put that as a separate trigger, with a lower sequence number. That way, if this line arrives, the trigger matches and the other ones don't have to be tested.
To check out which is faster - one trigger with many match paths, or lots of individual triggers, I wrote a small test routine that generated 1000 random match strings, and either generated 1000 triggers, or 1 trigger with 1000 alternate matches inside it.
This is the code:
function gentriggers ()
MtSrand (1) -- seed generator
-- method 1 - different triggers
--[[
for i = 1, 1000 do
match = utils.tohex (utils.md5 (tostring (MtRand ())))
AddTrigger("", match,
"", trigger_flag.Enabled , custom_colour.Custom2, 0, "", "")
end -- for
--]]
-- method 2 - one big trigger
regexp = "^("
for i = 1, 1000 do
if i ~= 1 then
regexp = regexp .. "|"
end -- if not first one
match = utils.tohex (utils.md5 (tostring (MtRand ())))
regexp = regexp .. match
end -- for
regexp = regexp .. ")$"
AddTrigger("", regexp,
"", trigger_flag.Enabled + trigger_flag.RegularExpression,
custom_colour.Custom2, 0, "", "")
end -- function
I initially used method 1 - 1000 triggers, then commented it out (as above) and tried method 2.
I let this generate the triggers for me, saved the world file, and then reconnected, and used the "info" window to see how much time had been spent on evaluating triggers (Shift+Ctrl+I).
These are the results:
- 1000 triggers - 0.29351 seconds
- 1 (big) trigger - 0.008946 seconds
It seems that one big trigger is 32 times as fast, so that should give you something concrete to decide on.
My test data was 324 lines received from the MUD, the connection data then the "help" information 10 times. Even using the slower method, it is matching 1000 triggers in under 1/1000 a second per line, so it is still pretty fast.
Since the triggers were just random data, then none matched, which is the worst-case scenario, as the incoming line has to be tested against all possibilities.
The trigger match text for the 1 trigger was:
^(8737703909D6F2E145E44444486B5205| ... (and so on) ... |754B497A32D72393529A99E36CE150FD|2304849F548D74B1F1B6336BBEFF9729)$
The triggers generated individually were:
<triggers>
<trigger
custom_colour="2"
enabled="y"
match="0029AA3F2BDAD35EE63281B77CD3FA98"
sequence="100"
>
</trigger>
</triggers>
(and another 999 like it)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|