create sparse array

JavaScript performance comparison

Test case created by kerryChen95

Preparation code

<script>
function arrayConstructor (i, length) {
  var arr;
  while(i--) {
    arr = new Array(length);
  }
  return arr;
}
function modifyArrayLength (i, length) {
  var arr;
  while(i--) {
    arr = [];
    arr.length = length;
  }
  return arr;
}

var loopCount = 10000;
var longLength = 1000;
var shortLength = 5;

arrayConstructor(loopCount, longLength).length === longLength || alert('arrayConstructor broken');
modifyArrayLength(loopCount, longLength).length === longLength || alert('modifyArrayLength broken');
</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
arrayConstructor(loopCount, longLength);
arrayConstructor(loopCount, shortLength);
pending…
modify array length
modifyArrayLength(loopCount, longLength);
modifyArrayLength(loopCount, shortLength);
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