It has less to do with RegExps and more to do with inline objects. You'll
note that I also moved inline functions out and declared them above. I'd,
eventually, like to do the same with inline arrays and object literals.
RegExp, Function, Array, and Objects shouldn't be re-declared on every
function call (or on every iteration in a loop!).

While very-simple RegExp optimizations may be a wash, performance-wise, (I
note that your test regexp is only against a couple characters and doesn't
even use a capturing expression) the code simplification and minification
benefits are very real. Going through this process I was able to remove a
large number of duplicate RegExp - and that's always a good thing.

--John


On Mon, Jul 20, 2009 at 9:20 AM, Ariel Flesler <afles...@gmail.com> wrote:

>
> Hi
>
> I've been seeing the multiple commits for
> http://dev.jquery.com/ticket/4111.
> Moving regexps to local vars to cache them.
>
> I was wondering if this is a perfomance measure and if so, if there's
> some benchmark out there to prove the gain.
> I personally think these changes make the code more complicated and
> longer. I'd rather see the regexp in place if I want to understand
> what it does.
>
> I went ahead and created a benchmark for this:
>  http://benchmarker.flesler.com/regexp/run/
>
> The conclusions were that there's absolutely no gain in speed except
> on IE. Even on IE, it doesn't seem to be such a critic improvement and
> it's slower the more you get away from the variables' scope chain (in
> nested functions).
>
> Any opinion ?
>
> Cheers
> --
> Ariel Flesler
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to