objmap literal vs dynamic yanche

JavaScript performance comparison

Test case created by yanche

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function addHandlerToObj(obj, name, handler) {
  obj[name]=handler;
  }
  
  function genFunction(ret){
  return function(){
  return ret;
  }
  }
  
  var fn20 = genFunction(20);
  
  var objMap = {};
  
  var fnList = new Array(20);
  for(var i=0;i<20;++i) {
  addHandlerToObj(objMap, "p"+i, fnList[i] = genFunction(i));
  }
  
  var keyArray = new Array(30);
  for(var i=0;i<30;++i) {
  keyArray[i]="p"+i;
  }
  
  var p0 = "p0";
  var p1 = "p1";
  var p2 = "p2";
  var p3 = "p3";
  var p4 = "p4";
  var p5 = "p5";
  var p6 = "p6";
  var p7 = "p7";
  var p8 = "p8";
  var p9 = "p9";
  var p10 = "p10";
  var p11 = "p11";
  var p12 = "p12";
  var p13 = "p13";
  var p14 = "p14";
  var p15 = "p15";
  var p16 = "p16";
  var p17 = "p17";
  var p18 = "p18";
  var p19 = "p19";
  
  var p0_nonintern = String.fromCharCode("p".charCodeAt(0), "0".charCodeAt(0));
  var p1_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0));
  var p2_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0));
  var p3_nonintern = String.fromCharCode("p".charCodeAt(0), "3".charCodeAt(0));
  var p4_nonintern = String.fromCharCode("p".charCodeAt(0), "4".charCodeAt(0));
  var p5_nonintern = String.fromCharCode("p".charCodeAt(0), "5".charCodeAt(0));
  var p6_nonintern = String.fromCharCode("p".charCodeAt(0), "6".charCodeAt(0));
  var p7_nonintern = String.fromCharCode("p".charCodeAt(0), "7".charCodeAt(0));
  var p8_nonintern = String.fromCharCode("p".charCodeAt(0), "8".charCodeAt(0));
  var p9_nonintern = String.fromCharCode("p".charCodeAt(0), "9".charCodeAt(0));
  var p10_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "0".charCodeAt(0));
  var p11_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "1".charCodeAt(0));
  var p12_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "2".charCodeAt(0));
  var p13_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "3".charCodeAt(0));
  var p14_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "4".charCodeAt(0));
  var p15_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "5".charCodeAt(0));
  var p16_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "6".charCodeAt(0));
  var p17_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "7".charCodeAt(0));
  var p18_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "8".charCodeAt(0));
  var p19_nonintern = String.fromCharCode("p".charCodeAt(0), "1".charCodeAt(0), "9".charCodeAt(0));
  var p20_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "0".charCodeAt(0));
  var p21_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "1".charCodeAt(0));
  var p22_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "2".charCodeAt(0));
  var p23_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "3".charCodeAt(0));
  var p24_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "4".charCodeAt(0));
  var p25_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "5".charCodeAt(0));
  var p26_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "6".charCodeAt(0));
  var p27_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "7".charCodeAt(0));
  var p28_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "8".charCodeAt(0));
  var p29_nonintern = String.fromCharCode("p".charCodeAt(0), "2".charCodeAt(0), "9".charCodeAt(0));
  
  var objLiteral = {
      "p0": fnList[0],
      "p1": fnList[1],
      "p2": fnList[2],
      "p3": fnList[3],
      "p4": fnList[4],
      "p5": fnList[5],
      "p6": fnList[6],
      "p7": fnList[7],
      "p8": fnList[8],
      "p9": fnList[9],
      "p10": fnList[10],
      "p11": fnList[11],
      "p12": fnList[12],
      "p13": fnList[13],
      "p14": fnList[14],
      "p15": fnList[15],
      "p16": fnList[16],
      "p17": fnList[17],
      "p18": fnList[18],
      "p19": fnList[19],
  };

};
</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
hit
(objLiteral[p17_nonintern] || fn20)();
pending…
miss
(objLiteral[p27_nonintern] || fn20)();
pending…

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

0 Comments