Collections

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var ids = 'kuqiecvx,zkaaoziq,causublr,memtagiu,obikiace,uaaqizco,oomzelfd,aapzaoea,uaxzevlo,fzacaoop,govxbiqo,uqjlaaib,sreweeeo,mmoaneib,xexaacoo,ulgqmepe,qxecoccw,ramolhhi,jvrokkuu,ihooggee,unigojfu,bbzaerue,ebeesuee,rhoabqxi,yeeliffe,xiwnruao,ilrvutoc,iixcoree,ewarzstu,ovbiapns,alnnojox,uaaateja,jikmweir,anivonao,esauwopv,agixutap,chyimepi,utaeauxo,leoowxot,ggzeeimf,inseeuul,qyiuaean,aukkudie,yivqqahe,nozocuyl,joziddox,fezuhada,uieqaapu,ueiojiyi,exomiwai,honijaum,qqqvufwv,atafeiso,eablewue,kaaatopt,uneraduu,eipatiea,kixpoopi,azafipik,vuimigut,vadgpmru,aiaypoke,oljiggok,hzonnaan,ezumkore,joobukto,ezapirup,zirhiopv,azufaaos,yeyuvbji,ruexddza,ffuusgni,bejdawia,erpiscme,auornhhi,eecifaoo,uodeabeg,ihvepeoi,iigfvufe,uzqemoqi,lzetnlus,pioeeheu,nfobbewi,ufhitwow,ibauzeeo,aataeili,uburorga,dbinwrae,ezowxxac,ofpnobix,pkopurom,lomideze,uijotidh,icieypoe,pouoekeo,afaxfhan,cciuoyif,hiantlpt,uippecuo,uagequlu,vkutteei,opuenuds,urnodohu,iayigqci,cweusuzw,hzknaiol,zejaooqo,qajiplkk,zeuvaige,koxtizre,itiaaoog,qxogacli,ujuapizu,krqmzzke,hahemuqa,ucolelvc,oazewgdu,fnknmuoe,qkafiima,oibwseoz,rsookooy,uuupidom,iahjitwi,zioyeepo,uxisueeo,akyualon,dxuuccao,pxuxaktq,uiuivvfy,bdasosai,zupeamcq,quejjkri,oevekfvi,pcominur,ukyisija,eqsyuaim,uoaetnew,xkpiloix,iuidadnm,uuoasqvc,ekbaeawg,dzisalpw,elureobe,ebwbnesi,qiaiwyaq,toiuiilo,vauotaca,ocemtouc,niazzerq,upawsfww,peyozine,cazzujun,awgpegmc,wvuvwdio,eshauaui,dolqqybo,itaweoyw,imwucqui,oqjhyuee,yodyusiq,giaiuiek,wauuduee,hikagouz,workfwio,evwqguib,emmomuco,nnayzsxe,ddwosyoo,zaesbiyb,xoyuooue,ugettiyy,sixwoxos,oluxools,mmadeesi,evuhadui,qidomohi,yxovoode,goremiyi,uaoavaee,ujhoijdd,eizdotua,oczqgewi,pbwxsynh,uvldalhe,pupexmag,cikariro,zzxeppla,lxrbotee,usooguhe,qagpseei,itobgkoj,zoddiwiv,uoekovwa,owuxlkai,izueeuuw,iidaaolt,rotofkzv,xipoaeew,akayxqof,poemiyoyi'.split(',');
  
  
  var map = new Map();
  
  var nameMap = {};
  var array = [];
  
  var object = {};
  
  ids.forEach(function(id){
  	var info = getObject(id);
  
  	map.set(id, info);
  
  	nameMap[id] = array.length;
  
  	array.push( info );
  	
  	object[id] = info;
  });
  
  
  function getObject(id){
  	return { id: id, count: Math.floor(Math.random()*100), created: Date.now() }
  }
  
  function get(id){
      for (var i=0;i<array.length;i++){
          if (array[i].id === id){
              return array[i]
          }
      }
  
      throw new Error('')
  }
  
  ids.sort(function(a,b){return -1+(Math.random()*2)})

};
</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
Maps
for (var i=0;i<ids.length;i++){
    map.get(ids[i])
}
pending…
Arrays
for (var i=0;i<ids.length;i++){
    get(ids[i])
}
pending…
Arrays(With an id map)
for (var i=0;i<ids.length;i++){
   array[nameMap[ids[i]]]
}
pending…
Objects
for (var i=0;i<ids.length;i++){
    object[ids[i]]
}
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