Array with/without defineProperty on prototype
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
With defineProperty |
|
pending… |
Without defineProperty |
|
pending… |
Without defineProperty, current page |
|
pending… |
Without defineProperty, current page, initializer |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments