I ran it around 15 times and the winner changes radically, both yield random
numbers between 40-80 in Chrome.Non-caching seems to win most of the time
but with the change rate, the numbers don't seem reliable.

On Mon, Jul 20, 2009 at 1:55 PM, John Resig <jere...@gmail.com> wrote:

> You need to be careful with your testing. Executing a function which has
> the regexp will result in non-deterministic results (the function call
> itself will probably take longer to run than the actual regexp being
> executed).
>
> A revised test:
> http://dev.jquery.com/~john/test/regexp.html
>
> Results (New vs. Old):
> FF 3.5   123ms  119ms
> SF 4.0      8ms     11ms
> IE 6.0    220ms  490ms
>
> As you can see, the new engines do optimize this quite well - but Internet
> Explorer is definitely a different matter.
>
> --John
>
>
> On Mon, Jul 20, 2009 at 10:28 AM, Ariel Flesler <afles...@gmail.com>wrote:
>
>> You're right, the regexps was too simple. I updated the test with longer
>> and more complex expression and the time is still the same.
>>
>> I agree about caching regexps that are re-used in many places, obviously.
>> Not so much about one-time expressions or strings.
>>  I'm really aware of how the different interpreters work, but it seems to
>> me that immutable literals (strings, numbers, regexps) are the first thing
>> I'd cache in a constant. Maybe current interpreters do that already
>> internally ?
>>
>> On Mon, Jul 20, 2009 at 12:56 PM, John Resig <jere...@gmail.com> wrote:
>>
>>> 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
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>> --
>> Ariel Flesler
>> http://flesler.blogspot.com
>>
>>
>>
>
> >
>


-- 
Ariel Flesler
http://flesler.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
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