Document fragment, one layer

JavaScript performance comparison

Revision 26 of this test case created by Julian

Preparation code

<div id='container'></div>
<script>
  var CONTAINER = document.getElementById('container'),
      RUN_TIMES_LOW = 20,
      RUN_TIMES_HIGH = 200,
      SOME_TEXT = 'Here is some inner text.';
</script>
      
<script>
Benchmark.prototype.teardown = function() {
  CONTAINER.innerHTML = '';

};
</script>

Preparation code output

<div id='container'></div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
No Fragment Low
for (var i = 0; i < RUN_TIMES_LOW; ++i) {
  var child = document.createElement('div');

  child.innerText = SOME_TEXT;

  CONTAINER.appendChild(child);
}
pending…
Fragment Low
var frag = document.createDocumentFragment();

for (var i = 0; i < RUN_TIMES_LOW; ++i) {
  var child = document.createElement('div');

  child.innerText = SOME_TEXT;

  frag.appendChild(child);
}

CONTAINER.appendChild(frag);
pending…
No Fragment High
for (var i = 0; i < RUN_TIMES_HIGH; ++i) {
  var child = document.createElement('div');

  child.innerText = SOME_TEXT;

  CONTAINER.appendChild(child);
}
pending…
Fragment High
var frag = document.createDocumentFragment();

for (var i = 0; i < RUN_TIMES_HIGH; ++i) {
  var child = document.createElement('div');

  child.innerText = SOME_TEXT;

  frag.appendChild(child);
}

CONTAINER.appendChild(frag);
pending…

Compare results of other browsers

Revisions

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

0 Comments