Array with/without defineProperty on prototype

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var Array1 = $("<iframe>").prop("src", "about:blank").appendTo("body").prop("contentWindow").Array;
    var Array2 = $("<iframe>").prop("src", "about:blank").appendTo("body").prop("contentWindow").Array;
   
    Object.defineProperty(Array1.prototype, "contains", {
      enumerable: false,
      configurable: false,
      writable: false,
      value: function(x) {
        return this.indexOf(x) > -1;
      }
    });
   
    var arr1 = new Array1(1, 2, 3, 4, 5);
    var arr2 = new Array2(1, 2, 3, 4, 5);
    var arr3 = new Array(1, 2, 3, 4, 5);
    var arr4 = [1, 2, 3, 4, 5];
};
</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
With defineProperty
for(var i = 0; i < arr1.length; i++) {
  arr1[i];
}
pending…
Without defineProperty
for(var i = 0; i < arr2.length; i++) {
  arr2[i];
}
pending…
Without defineProperty, current page
for(var i = 0; i < arr3.length; i++) {
  arr3[i];
}
pending…
Without defineProperty, current page, initializer
for(var i = 0; i < arr4.length; i++) {
  arr4[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