On Jan 19, 2008, at 9:39 PM, cjl wrote:
Karl: Thanks again. One last bug in the code you posted above, in the $ ('div.flag').each function, the assignment: var $this = $(this); Needs to take place before the if-else statements.
Oops. Right. Good catch. :-)
Overall, you improved code runs in approximately 1 second...down from 4 seconds for my original code. Wow!
Great!
FYI -- according to Firebug, chaining the before and after doesn't seem to make any real difference in performance.
very interesting. oh well. worth a try.
Out of curiosity, you wrote your for loops differently than I did, for example: Me: for (z=0;z<comments[i].length;z++) You: for (var z=0, c=comments[i].length;z<c;z++) Is there a difference?
Well, I haven't run a performance test on the two myself, but I've read that there are speed gains when using a variable for the count rather than an array length. Apparently, the array length is checked on each iteration. I've also read that you might be able to get a further boost by putting the count variable before the loop. Like this:
c=comments[i].length; for (var z=0;z<c; z++) --Karl _________________ Karl Swedberg www.englishrules.com www.learningjquery.com