sparse array to dense array

JavaScript performance comparison

Test case created by kerryChen95

Preparation code

<script>
function joinAndSplitWithAChar (len) {
  return new Array(len + 1).join('a').split('');
}
function joinAndSplitWithNum1 (len) {
  return new Array(len + 1).join('1').split('');
}
function arrayApply (len) {
  return Array.apply(null, new Array(len));
}

var longLength = 1000;
var shortLength = 5;

joinAndSplitWithAChar(longLength).length === longLength || alert('joinAndSplitWithAChar broken');
joinAndSplitWithNum1(longLength).length === longLength || alert('joinAndSplitWithNum1 broken');
arrayApply(longLength).length === longLength || alert('arrayApply 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
join and split with a character
joinAndSplitWithAChar(longLength);
joinAndSplitWithAChar(shortLength);
pending…
join and split with number 1
joinAndSplitWithNum1(longLength);
joinAndSplitWithNum1(shortLength);
pending…
array apply
arrayApply(longLength);
arrayApply(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