create-divs

JavaScript performance comparison

Test case created by create

Preparation code

<div id="t"></div>
<script>
Benchmark.prototype.setup = function() {
    function create(config, parent) {
      var e;
      for (var i = 0; i < config.length; i++) {
        e = document.createElement(config[i].type);
        for (var j = 0; j < config[i].classes.length; j++) {
          e.classList.add(config[i].classes[j]);
        }
        if (config[i].childs && config[i].childs.length > 0) {
          create(config[i].childs, e);
        }
        parent.appendChild(e)
      }
    }
};

Benchmark.prototype.teardown = function() {
    console.log(document.getElementById('t').innerHTML);
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
html
document.getElementById('t').innerHTML = '';
document.getElementById('t').innerHTML = '<div class="a b"><div class="c"></div><div class="e"></div></div>';
pending…
_js
var t = document.getElementById('t'),
  config = [{
    type: 'div',
    classes: ['a', 'b'],
    childs: [{
      type: 'div',
      classes: ['c']
    }, {
      type: 'div',
      classes: ['e']
    }]
  }];
while (last = t.lastChild) t.removeChild(last);
create(config, t);
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