|
Meylot Newbie
Joined: 20 Jun 2007 Posts: 5 Location: Somewhere in Middle Europa
|
Posted: Sat Jun 23, 2007 9:06 am
cMUD patterns or regexp |
I've tested the time of text matching in two ways: by the cMUD's pattern and perl regexp
Using
#IF (text=~pattern)
turned out to be between a few and more than 10 times faster than
#IF (%regex(text,pattern))
What is the reason of that, and does it mean, that using cMUD patterns instead of perl regexp patterns in triggers gives better time performance? (with appreciable difference) |
|
|
|
Thinjon100 Apprentice
Joined: 12 Jul 2004 Posts: 190 Location: Canada
|
Posted: Sat Jun 23, 2007 5:02 pm |
All CMud patterns are converted into regex in the background... the difference you're seeing is likely due to WHAT pattern it's been converted into... some patterns take less processing time than others and from what I can tell, the CMud format doesn't use very complex regex patterns when it converts.
|
|
_________________ If you're ever around Aardwolf, I'm that invisible guy you can never see. Wizi ftw! :) |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sat Jun 23, 2007 5:30 pm |
Recall that cMUD pattern is already optimized by the application and is likely to be processed faster that way. With the latter you have the overhead of the function call and the probability that this pattern needs to be compiled when it hits the underlying Perl Regex library.
Zugg is likely is the only one who can answer this definitively. |
|
_________________ Asati di tempari! |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jun 25, 2007 5:48 pm |
Yes, the (test=~pattern) is always going to be faster. The %regex version has the overhead of a function call, whereas the =~ operator is handled within the compiler itself.
|
|
|
|
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Mon Jun 25, 2007 7:09 pm |
How about adding the syntax (test =~ /regexp/) to allow for regexp comparisons without using the function?
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jun 25, 2007 7:30 pm |
The parser won't handle strings delimited by characters other than "", so it's not an easy change unfortunately. I'll consider that in the future, but for now you should just try to use normal patterns instead of regexp.
|
|
|
|
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Mon Jun 25, 2007 8:28 pm |
I find I use many more regexps than simple patterns. On the other hand, I rarely use pattern matching in #IF's anyways... Another suggestion would be to create a new pattern wildcard that means "Use a regexp from here". So you could do something line (test =~ "%/regexp") to do this within the rules of your lexer.
|
|
|
|
|
|