Converting arguments to an array (v21)

Revision 21 of this benchmark created by Calvin on


Setup

var resultLarge, resultSmall, resultMedium;  
    
    
      var largeArray = Array(1001).join("a").split("");
      var mediumArray = Array(101).join("a").split("");
      var smallArray = Array(6).join("a").split("");

Test runner

Ready to run.

Testing in
TestOps/sec
Array#slice
resultLarge = largeArray.slice();
resultMedium = mediumArray.slice();
resultSmall = smallArray.slice();
ready
Array#push
resultLarge = [];
Array.prototype.push.apply(resultLarge,largeArray);
resultMedium = []
Array.prototype.push.apply(resultMedium,mediumArray);
resultSmall = []
Array.prototype.push.apply(resultSmall,smallArray);
ready
Array#unshift
resultLarge = [];
Array.prototype.unshift.apply(resultLarge,largeArray);
resultMedium = []
Array.prototype.unshift.apply(resultMedium,mediumArray);
resultSmall = []
Array.prototype.unshift.apply(resultSmall,smallArray);
ready
Array
resultLarge = Array.call(null, largeArray);
resultMedium = Array.call(null, mediumArray);
resultSmall = Array.call(null, smallArray);
ready
while loop
var i, len;

i = -1;
len = largeArray.length;
resultLarge = new Array(len);
while (++i < len) {
   resultLarge[i] = largeArray[i];
}

i = -1;
len = mediumArray.length;
resultMedium = new Array(len);
while (++i < len) {
   resultMedium[i] = mediumArray[i];
}

i = -1;
len = smallArray.length;
resultSmall = new Array(len);
while (++i < len) {
   resultSmall[i] = smallArray[i];
}
ready
Array#concat
resultLarge = largeArray.concat();
resultMedium = mediumArray.concat();
resultSmall = smallArray.concat();
if (resultLarge === largeArray) {
    throw new Error('supposed to be different');
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.