Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Help on using alternation grouping star versus dot star.by ZZamboni (Curate) |
on Jun 10, 2001 at 08:41 UTC ( [id://87274]=note: print w/replies, xml ) | Need Help?? |
Although your application is in JavaScript, the question itself
is about regular expressions. Benchmark reports (output edited for
briefness, code at the end):
So it seems that method 2 is the best, but not by much, followed closely by method 3, and method 1 is a distant third. Almost the opposite of what you originally thought! I'll let the experts (if they want) explain why this is, in terms of how the regex parser operates, but my guess is that 2 is faster because most characters are not opening angle brackets, so the [^<]* absorbs them. I also have the feeling that the comparison may change when confronted with real data, because of the length and contents of whatever is inside the <div> tags. Update: and of course, all of this only applies to the Perl implementation of regular expressions, so these results are probably mostly useless, because different JavaScript implementations could do things differently. --ZZamboni
In Section
Seekers of Perl Wisdom
|
|