Converting arguments to an array

JavaScript performance comparison

Revision 14 of this test case created by

Preparation code

<script>
  function arrayProtoSlice() {
      return Array.prototype.slice.apply(arguments);
  }

  function arrayLiteralSlice() {
      return [].slice.apply(arguments);
  }

  var slice = [].slice;
  function closure() {
    return slice.call(arguments);
  }

  function splice() {
      return [].splice.call(arguments, 0);
  }
  function push() {
      var x = [];
      x.push.apply(x, arguments);
      return x;
  }
  function unshift() {
      var x = [];
      x.unshift.apply(x, arguments);
      return x;
  }
  function whileDec() {
      var arr = [],
      i = arguments.length;
      while(i--) {
          arr[i] = arguments[i];
      }
      return arr;
  }
  function arrayApply() {
      return Array.apply(null, arguments);
  }

  var bigArray = new Array(1001).join("a").split("");
  var smallArray = new Array(6).join("a").split("");
  
  unshift.apply(null, bigArray).length === bigArray.length || alert('unshift broken');
  push.apply(null, bigArray).length === bigArray.length || alert('push broken');
  splice.apply(null, bigArray).length === bigArray.length || alert('splice broken');
  arrayProtoSlice.apply(null, bigArray).length === bigArray.length || alert('arrayProtoSlice broken');
  arrayLiteralSlice.apply(null, bigArray).length === bigArray.length || alert('arrayLiteralSlice broken');
whileDec.apply(null, bigArray).length === bigArray.length || alert('arrayLiteralSlice broken');
  arrayApply.apply(null, bigArray).length === bigArray.length || alert('arrayAppy broken');
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Array prototype slice
arrayProtoSlice.apply(null, bigArray);
arrayProtoSlice.apply(null, smallArray);
pending…
Array literal slice
arrayLiteralSlice.apply(null, bigArray);
arrayLiteralSlice.apply(null, smallArray);
pending…
Array push
push.apply(null, bigArray);
push.apply(null, smallArray);
pending…
Array splice
splice.apply(null, bigArray);
splice.apply(null, smallArray);
pending…
Unshift
unshift.apply(null, bigArray);
unshift.apply(null, smallArray);
pending…
Closure
closure.apply(null, bigArray);
closure.apply(null, smallArray);
pending…
While loop
whileDec.apply(null, bigArray);
whileDec.apply(null, smallArray);
pending…
Array Apply
arrayApply.apply(null, bigArray);
arrayApply.apply(null, smallArray);
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.

3 Comments

kerryChen95 commented :

Add a new way to convert arguments object to array by Array.apply(null, argument), and this way seems to be the fastest.

kerryChen95 commented :

sorry, typo in last comment. That codes should be Array.apply(null, arguments)

aa commented :

mt1125 http://www.coachoutletmalls.us.com http://www.pandora-uk.me.uk http://www.monclerjacketsuk.org.uk http://www.burberryoutletsale.com.co http://www.ralphlaurensaleclearance.org.uk http://www.ugg-boots.net.co http://www.uggs--canada.ca http://www.coach-outlets.us.com http://www.uggsoutletclearance.us.com http://www.canadiangoose.us.com http://www.longchamphandbagsuk.org.uk http://www.ferragamo-outlet.us.com http://www.uggsoutlet.cc http://www.katespade.in.net http://www.longchampoutletus.us.com http://www.ugg-boots.org.uk http://www.jordanretro.name http://www.cheapjerseyswholesalefromchina.us.com http://www.ugg-uk.org.uk http://www.uggoutlets.in.net http://www.toryburchoutletonline.com.co http://www.pandora-outlet.us.com http://www.harden-vol1.com http://www.adadassuperstar.com http://www.louisvuittonoutlet.us.org http://www.cheapuggs-boots.us.com http://www.ralphlaurenoutletonline-polo.us.com http://www.cheapuggs.net.co http://www.columbiasportswear.us.com http://www.uggs-boots.fr http://www.pandora-charms.us.org http://www.oakley--sunglasses.us.org http://www.thenorthfacejacketsoutlet.us.com http://www.moncleroutlet.me.uk http://www.coachoutletonlinecoachfactoryoutlet.us.com http://www.ralph-laurenuk.org.uk http://www.yeezyboost.org.uk http://www.moncleroutletonlines.us.com http://www.ugg.net.co http://www.nikeoutlet.us.com http://www.coachcanadaoutlet.ca http://www.korsmichaeloutlet.us.com http://www.canadagoosejacketscanada.ca http://www.adidasoutlet.us.com http://www.ugg-outletstores.us.com http://www.nike-store.us.com http://www.canadagooseukjackets.org.uk http://www.uggaustraliaoutlet.com.co http://www.burberry-outlet-canada.ca http://www.coach-factoryoutlet-online.us.com http://www.canadagooseoutletcanada.com.co http://www.outletmichaelkorsonline.us.com http://www.adidasnmd.us.org http://www.cheapmlbjerseyschina.us.com http://www.uggbootsonline.us http://www.mlbjerseyscheap.us.com http://www.timberland-outlets.us http://www.adidasnmd-shoes.us http://www.cheap-raybans.us.com http://www.uggoutlet.cc http://www.supremeclothing.us.org http://www.canadagooseoutletonlines.us http://www.coach-factoryoutletonline.us.org http://www.hermes-handbags.us http://www.canadagooseoutletjackets.ca http://www.canadagoosejacketsoutlet.name http://www.uggs-outlets.com.co http://ugg.bootsoutlet.us.com http://www.uggcanadaboots.ca http://www.uggshoes.us.com http://www.salvatoreferragamoshoes.us.com http://www.pandora.us.com http://www.airjordans.us.com http://www.canadagoosejacketscoats.org.uk http://www.yeezyboost-350.co.uk http://www.oakley.nom.co http://www.moncler-outlet.us.org http://www.coachfactory-outlet.us.com http://www.michaelkorsoutlets.us.com http://www.canadagoosejackets-outlet.us http://www.supremeclothing.org.uk http://www.uggsaustraliaoutlet.us.com http://www.uggsbootsonline.us.com http://www.canadagooseoutletjackets.us http://www.guccioutlets.us.org http://www.coachfactoryoutletsonlines.us.com http://www.outletcanadagoose.us http://www.jacketscanadagoose.com.co http://www.outletcoachoutlet.us.com http://www.canadagooseukjackets.me.uk http://www.adidas-yeezyshoes.us.com http://www.canadagooseoutletjackets.com.co http://www.michaelkorsoutletclearance.in.net http://www.adidas-shoes.us.com http://www.canadagooseoutlet.cc http://www.uggaustraliaoutlet.in.net http://www.louisvuitton-outletonline.us.com http://www.coachoutlet-onlinesale.us.com http://www.polooutlets.us.org http://www.coachfactory-outletstore.us.com http://www.ralphlauren.me.uk http://www.cheapnfljerseysofficial.us.com http://www.canadagooseoutletstores.us http://www.ralphlaurenoutlet.us.org http://www.hermesbirkin.in.net http://www.cheapoakleysunglassesofficial.us.com http://www.hermesbag.us.com http://www.coachoutletcanada.ca http://www.yeezyboost-350.us.com http://www.nikeairmax.in.net http://wwwcanadagoose-jacketsuk.com.co http://www.pandora-jewelryoutlet.us.com http://www.pandoracharmssaleclearance.uk http://www.ralphlaurenoutletsale.us.com http://www.uggsoutlets.name http://www.uggoutlets.name http://www.ugg-outlets.us http://www.coach-outletonlines.us.com http://www.fredperrypoloshirts.us http://www.outletlouisvuitton.us.com http://www.coachoutletstoreonline.com.co http://www.canadagooseoutlet-jackets.us http://www.burberry.us.com http://www.canadagoosejacketscanada.com.co http://www.michael-korsoutlets.us.com http://www.pandoracharms.name http://www.birkenstocks.us http://www.canadagoose-outlet.name http://www.uggbootsclearance.org.uk http://www.ralphlaurenoutlet.in.net http://www.longchamp-outlet.us.com http://www.redbottomsshoes.us.com http://www.michaelkorsoutlet1.us.com http://www.michael-korshandbags.me.uk http://www.raybansunglasses.net.co http://wwwmonclerjacketsuk.com.co http://www.yeezyboost.us.com http://www.catboots.us http://www.mulberryoutlet.org.uk http://www.coachoutlet-online.us.org http://www.canadagooseoutlets.us http://www.canadagooseoutletus.us.com http://www.nikeshoes.in.net http://www.monclerjacketsoutlet.in.net http://www.pandoracharms-uk.org.uk http://www.uggs-boots.us http://www.uggoutlet-store.us http://www.mbtshoes.name http://www.louisvuitton-outlet.us.com http://www.northfacejacketssale.us.com http://www.michaelkorsfactoryoutletsale.us.com http://www.christianlouboutinshoes.us.org http://www.raybanssunglassesoutlet.us.com http://www.polo-ralphlauren.in.net http://www.uggs-australia.it http://www.uggsoutletonlines.us.com http://www.ralphlauren-outletpolo.us.com http://www.uggs-clearance.us.com http://www.uggsboots.name http://www.canadagoosesalejackets.us.com http://www.michaelkors-outlet.ca http://www.pandoracharms.us.com http://www.monclerjacketssale.us.com http://www.supremenewyork.us.com http://www.cheapuggssale.com.co http://www.nikeoutletonline.us.com http://www.uggbootssales.us.com http://www.ralphlaurensaleclearance.me.uk http://www.cheapuggs.com.co http://www.coachhandbagsoutlet.us.com http://www.ralph-laurenoutlet.com.co http://www.guccihandbagsoutlet.us.com http://www.michaelkorsoutletonlinemichaelkors.us.com http://www.katespadehandbagsclearance.us.com http://www.canadagooseoutletjackets.us.com http://www.coachoutletsonlines.us.com http://www.uggoutlet-clearance.us.com http://www.coachoutletstoreonlineclearances.in.net http://www.pandorajewelryoutlet.in.net http://www.louboutinshoes.in.net http://www.northface-jackets.us.com http://www.jacketscanadagoose.org.uk http://www.ralphlaurenoutlet-polo.us.com http://www.tomsoutlets.us.com http://www.michaelkorsoutlet.co.uk http://www.adidas-superstar.us.com http://www.uggsoutletstoreonline.us.com http://www.vuittonlouis.us.com http://www.uggsaustralia.fr http://www.ralphlaurenuk.me.uk http://www.northfaceoutlet.us.com http://www.coach-factory-outlet.us.org http://www.uggoutletonlines.us http://www.ultraboost.us http://www.michael-korsoutlet.ca http://www.valentinoshoesoutlets.us.com http://www.canadagoosejacket.com.co http://www.uggs.net.co http://www.cheapjordan-shoes.in.net http://www.outletcoachonline.us.com http://www.cheapjordans.in.net http://www.coachoutletus.us.com http://www.cheapraybansunglassessale.us.com http://www.cheapmlbjerseys.us http://www.cheapjordans.com.co http://www.adidasyeezyshoes.us.com http://www.fitflopssale.us.com http://www.canadagooseoutlet.name http://wwwcanadagoose-uk.com.co http://www.nfljerseyscheapwholesale.us.com http://www.pandoracharms.com.co http://www.mbtshoes.us.org http://www.outletcanadagooseoutlet.us.com http://www.cheapoakleysunglasses.com.co http://www.thenorthface.us.com http://www.airjordanshoes.in.net http://www.michael-korsoutlet.us.com http://www.uggbootsoutletstores.us.com http://www.coachfactory-outletonline.us.org http://www.moncler-outlets.us.com http://www.air-jordans.us.com http://www.uggsbootscanada.ca http://www.christianlouboutinoutlet.us http://www.adidasshoe.us.com http://www.michaelkorsoutletshopping.us.com http://www.cheapuggboots.us.com http://www.adidas-outlet.us.com http://www.timberlandbootsoutlets.us.com http://www.uggsonsale.us.com http://www.uggbootsclearance.com.co http://www.ralphlaurenoutletpolo.org.uk http://www.northfacejacketsoutlet.com.co http://www.coach-outletonline.us.org http://www.adidas-nmd.us.com http://www.burberryoutlet.in.net http://www.michaelkorsoutletonlineclearance.in.net http://www.toryburchoutletonlines.us.com http://www.katespadeonlineoutlet.us.com http://www.poloralphlaurenoutletonline.us.com http://www.doudounemonclerpascher.fr http://www.uggbootsoutletsale.us.com http://www.cheapraybans.com.co http://www.cheapjordans-shoes.us.com http://www.2017nikeairmax.us http://www.polooutlet.in.net http://www.nikeoutlet.in.net http://www.red-bottoms.us.com http://www.kate-spade.us.com http://www.coachfactoryoutlet-storeonline.us.com http://www.canadagoose-jacketsoutlet.us http://www.uggoutlet-onlines.us.com http://www.coachoutlets.us.org http://www.cheapjordanshoes.us.com http://www.coachfactoryonlineoutlet.com.co http://www.uggoutletonline.name http://www.uggs-boots.us.org http://www.canadagoosesaleoutlet.us.com http://www.uggoutlets.us.org http://www.mulberry-bags.me.uk http://www.uggsoutlets.us.org http://www.nikeshoes.us.com http://www.uggoutletstore.name http://www.hermes.us.org http://www.moncleroutlets.us.org http://www.canadagoosesoutlet.ca http://www.ralph-laurenoutlet.org.uk http://www.canadagoosejacketssale.com.co http://www.airmax-2018.com http://www.canadagooseclothing.us.com mt1125