That's a fantastic improvement. But now I have a new challenge - keep
reading...

To see if there really is a difference between the 2nd and 3rd
options, or whether it is just 'variance', I cranked up the DIVs & Ps
and tried both versions again:

ALL tests below are in FireFox 3.0.6
--------------------------------------------

jQuery version used   = 1.3.2
Total number of DIVs = 1000
Paragraphs per DIV   = 500
-----------------------------------
$("#div500 p") = 15916ms
$("p", "#div500") = 32ms
$("#div500").find("p") = 2ms


jQuery version used   = 1.3.3pre
Total number of DIVs = 1000
Paragraphs per DIV   = 500
-----------------------------------
$("#div500 p") = 48ms
$("p", "#div500") = 4ms
$("#div500").find("p") = 4ms

The last two tests seem identical, but the first syntax is still 0-
times slower in 1.3.3.

I though the 1st syntax might be slower because it handles *a range of
possible syntaxes*, like $("#div500 > p"). So I add 2 new syntaxes and
ran the test again...

jQuery version used   = 1.3.3pre
Total number of DIVs = 1000
Paragraphs per DIV   = 500
-----------------------------------
$("#div500 p") = 34ms
$("p", "#div500") = 2ms
$("#div500").find("p") = 3ms
$("#div500 > p") = 16396ms
$("#div500").children("p") = 32ms

WOW! Check out the last 2 tests, John. Syntax #4 takes 512-times
longer than #5! I think this code needs a little TLC too ;)

It was also interesting that $("#div500").children("p") is 10-times
slower than $("#div500").find("p"). So I added one final test using
childNodes and filter() to see if I could beat .children()...

jQuery version used   = 1.3.3pre
Total number of DIVs = 1000
Paragraphs per DIV   = 500
-----------------------------------
$("#div500 p") = 55 ms
$("p", "#div500") = 2 ms
$("#div500").find("p") = 3 ms
$("#div500 > p") = 14802 ms
$("#div500").children("p") = 32 ms
$( $("#div500")[0].childNodes ).filter("p") = 19 ms

The last (childNodes) test gathers the same elements in half the time.
The 32ms performance of children("p") is very good, but perhaps there
is still room for improvement?

/Kevin


On Feb 25, 1:30 pm, John Resig <jere...@gmail.com> wrote:
> To follow-up from my post yesterday, here are the new numbers, for
> 1.3.3 (work in progress, naturally):http://ejohn.org/files/jquery1.3.3/id.html
>
> jQuery version used   = 1.3.3pre
> Total number of DIVs = 100
> Paragraphs per DIV   = 50
> -----------------------------------
> $("#div50 p") = 2ms
> $("p", "#div50") = 0ms
> $("#div50").find("p") = 1ms
>
> --John

Reply via email to