On 17/08/07, Rob Desbois <[EMAIL PROTECTED]> wrote:
> Does anyone know offhand how much overhead using .add() instead of the comma
> incurs?
> Is it just the additional function call?
> --rob

It is likely to be an additional function call or two, so the
difference is negligible. If you have the Firebug extension
(http://getfirebug.com/) for Firefox you can time this kind of stuff.
It's not perfect, but on http://docs.jquery.com/Main_Page the
following code:

---

var count = 100;

console.time('comma');
    for ( var i = 0; i < count; i++ )
        $('h1,h2');
console.timeEnd('comma');

console.time('.add()');
    for ( var i = 0; i < count; i++ )
        $('h1').add('h2');
console.timeEnd('.add()');

---

...produced the following times:

comma: 76ms
.add(): 89ms

comma: 77ms
.add(): 89ms

comma: 76ms
.add(): 88ms

(I usually run profiling code like this several times as results can
sometimes vary).

---

So yeah, ~12ms difference when called 100 times - negligible. It's
down to your personal preference I guess.


-- 
Best wishes,
Dave Cardwell.

http://davecardwell.co.uk/javascript/jquery/

Reply via email to