Re:The DOM isn't slow
by mikepurvis on Tuesday March 19, 2013 @10:55AM
(#5401230)
Interesting. On a whim, I tried changing your fiddle to use Array.join construction rather than string appends, but string appends remain 5-10% faster:
That way uses an indexed for-loop, but the while loop with Array.push was just as bad.
Re:The DOM isn't slow
by iwillreply on Tuesday March 19, 2013 @11:12AM
(#5401343)
Interesting, I very briefly deliberated while vs for, and how the performance of both had changed since last look.
But checking at: https://blogs.oracle.com/greimer/resource/loop-test.html
Still seemed to demonstrate a decreasing while loop as the fastest in my test.
Re:The DOM isn't slow
by Guillaume86 on Tuesday March 19, 2013 @10:47AM
(#5401181)
You just use innerHTML with a big string, it's not the equivalent of the original fiddle and it's not a fair comparison.
Re:The DOM isn't slow
by latviancoder on Tuesday March 19, 2013 @10:50AM
(#5401197)
Here is a comparison, that looks more fair to me:
Why not? The original fiddle uses a documentFragment and does a bulk-insert of that in the document itself.
Dude, you aren't creating dom nodes.
Here is the equivalent:
Re:The DOM isn't slow
by iwillreply on Tuesday March 19, 2013 @11:03AM
(#5401282)
Why would you append on every loop. Rather than build the string and then append the whole lot on one block?
If you compare the DOM of the original fiddle and the DOM of following the fiddle I posted. You will see they are the same.
I'm not saying what I referenced is the 'best' way of doing things. But that the debate in the original article (based on the provided examples) is pretty null.
You're right, my example was different. But upon fixing it to match the original article's example, but with jQuery creating the dom nodes, it is still slower
Writing this utilising jQuery for DOM manipulation ( http://jsfiddle.net/YNxEK/7/ ) is getting me consistently faster results than the original fiddle ( http://jsfiddle.net/YNxEK/ ) on Firefox and Chrome.