The Power Of Getters - appendChild

JavaScript performance comparison

Test case created by WebReflection

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function Element_inline() {this.children = []}
  Element_inline.prototype.appendChild = function (el) {
    this.children.push(el);
    this.firstChild = this.children[0];
    // to make the test meaningful with the logic
    // implemented later on ... this is:
    this.lastChild = this.children[
      this.children.length - 1
    ];
    // instead of this.lastChild = el;
    return el;
  };
  var ei = new Element_inline;
  
  function Element_later() {this.children = []}
  Element_later.prototype.appendChild = function (el) {
    delete this.firstChild;
    delete this.lastChild;
    this.children.push(el);
    return el;
  };
  var el = new Element_later;
  
  var result;

};
</script>

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
Element_inline
result = ei.appendChild({});
pending…
Element_later
result = el.appendChild({});
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