Create an array of initial size

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr, size = 1e3, undef;
};
</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
Array constructor
arr = Array(size);
pending…
for loop + push
arr = [];
for (var i = 0; i < size; ++i) {
  arr[i] = undef;
}
 
pending…
while loop, forwards
var i = 0;
arr = [];
while (i++ < size) {
    arr[i] = undef;
}
pending…
while loop, backwards
var i = size;
arr = [];
while (i-- > 0) {
    arr[i] = undef;
}
pending…
sparse array
arr = [];
arr[size - 1] = undef;
pending…
length
arr = [];
arr.length = size;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment