console.time("$('p span')"); for(var i = 0; i < 1000; i++) $('p span'); console.timeEnd("$('p span')");
console.time("$('p').find('span')"); for(var i = 0; i < 1000; i++) $('p').find('span'); console.timeEnd("$('p').find('span')"); $('p span'): 863ms $('p').find('span'): 3050ms And from the profiler: $('p span'): 390 function calls $('p').find('span'): 830 function calls Though the function is always "e", so it isn't very useful for actual profiling, but at least it gives you an idea of how much work is being done. --Erik On 12/4/07, Gordon <[EMAIL PROTECTED]> wrote: > > > I couldn't tell you which one is faster, but if you want to find out > for yourself then you can use the profiler in FireBug. It's an addon > for FireFox that has some powerful javascrip tools included. Write a > short script with a function that runs the selector you want to > profile in a loop, say 100 iterations, and then call it while the > profiler is running. > > On Dec 3, 10:58 pm, sawmac <[EMAIL PROTECTED]> wrote: > > is there a difference in performance for these two: > > > > $('p span') > > > > $('p').find('span') > > > > while, I'm on the subject, what's a good way to test performance of > > queries (and scripts in general) > > > > thanks > > > > --dave >