Chained/nested DOM modification vs "the long way"

JavaScript performance comparison

Test case created by Justin Stallings

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
The long way
var s = document.createElement('span'),
  p = document.createElement('p'),
        b = document.createElement('button'),
        f = document.createDocumentFragment();

s.innerHTML = 'span';
b.innerHTML = 'clicky';

p.appendChild(s);

f.appendChild(p);
f.appendChild(b);
pending…
Chained/nested
var sd = document.createDocumentFragment();
sd.appendChild(document.createElement('p')).appendChild(document.createElement('span')).innerHTML = 'span';
sd.appendChild(document.createElement('button')).innerHTML = 'clicky';
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment