The Power Of Getters - Element

JavaScript performance comparison

Test case created by WebReflection

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Element_Classic() {
      this.children = [];
    }
   
    function Element_Getter() {}
    Object.defineProperty(
      Element_Getter.prototype,
      "children", {
      get: function () {
        return Object.defineProperty(
          this, "children", {value: []}
        ).children;
      }
    });
   
    var result;
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Element_Classic
result = new Element_Classic;
pending…
Element_Classic_children
result = new Element_Classic;
for(var i = 0; i < 100; i++) {
  result.children.push(i);
}
pending…
Element_Getter
result = new Element_Getter;
pending…
Element_Getter_children
result = new Element_Getter;
for(var i = 0; i < 100; i++) {
  result.children.push(i);
}
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