Switch vs Hash vs Others (v43)

Revision 43 of this benchmark created by Chris on


Preparation HTML

<script>
var foo = 0;
</script>

Setup

foo = 0;
  var curTest = 0;
  var actions = {
  0: function() { foo += 238;},
  1: function() { foo += 20;},
  2: function() { foo += 228;},
  3: function() { foo += 130;},
  4: function() { foo += 33;},
  5: function() { foo += 55;},
  6: function() { foo += 88;},
  7: function() { foo += 3;},
  8: function() { foo += 170;},
  9: function() { foo += 49;},
  10: function() { foo += 18;},
  11: function() { foo += 88;},
  12: function() { foo += 117;},
  13: function() { foo += 216;},
  14: function() { foo += 106;},
  15: function() { foo += 131;},
  16: function() { foo += 138;},
  17: function() { foo += 165;},
  18: function() { foo += 90;},
  19: function() { foo += 216;},
  20: function() { foo += 154;},
  21: function() { foo += 203;},
  22: function() { foo += 6;},
  23: function() { foo += 74;},
  24: function() { foo += 24;},
  25: function() { foo += 66;},
  26: function() { foo += 49;},
  27: function() { foo += 22;},
  28: function() { foo += 83;},
  29: function() { foo += 234;},
  30: function() { foo += 192;},
  31: function() { foo += 174;},
  32: function() { foo += 234;},
  33: function() { foo += 13;},
  34: function() { foo += 193;},
  35: function() { foo += 186;},
  36: function() { foo += 125;},
  37: function() { foo += 68;},
  38: function() { foo += 217;},
  39: function() { foo += 100;},
  40: function() { foo += 237;},
  41: function() { foo += 32;},
  42: function() { foo += 181;},
  43: function() { foo += 4;},
  44: function() { foo += 145;},
  45: function() { foo += 237;},
  46: function() { foo += 189;},
  47: function() { foo += 6;},
  48: function() { foo += 129;},
  49: function() { foo += 108;},
  50: function() { foo += 219;},
  51: function() { foo += 50;},
  52: function() { foo += 206;},
  53: function() { foo += 93;},
  54: function() { foo += 120;},
  55: function() { foo += 91;},
  56: function() { foo += 21;},
  57: function() { foo += 164;},
  58: function() { foo += 32;},
  59: function() { foo += 184;},
  60: function() { foo += 82;},
  61: function() { foo += 126;},
  62: function() { foo += 170;},
  63: function() { foo += 72;},
  64: function() { foo += 108;},
  65: function() { foo += 0;},
  66: function() { foo += 200;},
  67: function() { foo += 155;},
  68: function() { foo += 129;},
  69: function() { foo += 150;},
  70: function() { foo += 105;},
  71: function() { foo += 117;},
  72: function() { foo += 229;},
  73: function() { foo += 4;},
  74: function() { foo += 201;},
  75: function() { foo += 202;},
  76: function() { foo += 173;},
  77: function() { foo += 190;},
  78: function() { foo += 39;},
  79: function() { foo += 188;},
  80: function() { foo += 177;},
  81: function() { foo += 9;},
  82: function() { foo += 167;},
  83: function() { foo += 222;},
  84: function() { foo += 48;},
  85: function() { foo += 198;},
  86: function() { foo += 121;},
  87: function() { foo += 16;},
  88: function() { foo += 103;},
  89: function() { foo += 70;},
  90: function() { foo += 56;},
  91: function() { foo += 75;},
  92: function() { foo += 94;},
  93: function() { foo += 108;},
  94: function() { foo += 58;},
  95: function() { foo += 42;},
  96: function() { foo += 123;},
  97: function() { foo += 107;},
  98: function() { foo += 31;},
  99: function() { foo += 99;},
  100: function() { foo += 213;},
  101: function() { foo += 98;},
  102: function() { foo += 88;},
  103: function() { foo += 229;},
  104: function() { foo += 169;},
  105: function() { foo += 160;},
  106: function() { foo += 14;},
  107: function() { foo += 217;},
  108: function() { foo += 172;},
  109: function() { foo += 170;},
  110: function() { foo += 246;},
  111: function() { foo += 93;},
  112: function() { foo += 217;},
  113: function() { foo += 18;},
  114: function() { foo += 229;},
  115: function() { foo += 18;},
  116: function() { foo += 68;},
  117: function() { foo += 28;},
  118: function() { foo += 99;},
  119: function() { foo += 194;},
  120: function() { foo += 240;},
  121: function() { foo += 210;},
  122: function() { foo += 79;},
  123: function() { foo += 151;},
  124: function() { foo += 185;},
  125: function() { foo += 88;},
  126: function() { foo += 75;},
  127: function() { foo += 66;},
  128: function() { foo += 50;},
  129: function() { foo += 188;},
  130: function() { foo += 44;},
  131: function() { foo += 79;},
  132: function() { foo += 107;},
  133: function() { foo += 42;},
  134: function() { foo += 232;},
  135: function() { foo += 165;},
  136: function() { foo += 238;},
  137: function() { foo += 36;},
  138: function() { foo += 80;},
  139: function() { foo += 150;},
  140: function() { foo += 25;},
  141: function() { foo += 26;},
  142: function() { foo += 60;},
  143: function() { foo += 9;},
  144: function() { foo += 78;},
  145: function() { foo += 192;},
  146: function() { foo += 76;},
  147: function() { foo += 79;},
  148: function() { foo += 33;},
  149: function() { foo += 186;},
  150: function() { foo += 61;},
  151: function() { foo += 198;},
  152: function() { foo += 20;},
  153: function() { foo += 50;},
  154: function() { foo += 57;},
  155: function() { foo += 233;},
  156: function() { foo += 180;},
  157: function() { foo += 208;},
  158: function() { foo += 132;},
  159: function() { foo += 29;},
  160: function() { foo += 233;},
  161: function() { foo += 37;},
  162: function() { foo += 23;},
  163: function() { foo += 44;},
  164: function() { foo += 12;},
  165: function() { foo += 159;},
  166: function() { foo += 34;},
  167: function() { foo += 177;},
  168: function() { foo += 51;},
  169: function() { foo += 15;},
  170: function() { foo += 86;},
  171: function() { foo += 124;},
  172: function() { foo += 7;},
  173: function() { foo += 247;},
  174: function() { foo += 57;},
  175: function() { foo += 96;},
  176: function() { foo += 225;},
  177: function() { foo += 244;},
  178: function() { foo += 166;},
  179: function() { foo += 77;},
  180: function() { foo += 48;},
  181: function() { foo += 123;},
  182: function() { foo += 110;},
  183: function() { foo += 49;},
  184: function() { foo += 167;},
  185: function() { foo += 174;},
  186: function() { foo += 208;},
  187: function() { foo += 25;},
  188: function() { foo += 43;},
  189: function() { foo += 106;},
  190: function() { foo += 199;},
  191: function() { foo += 168;},
  192: function() { foo += 155;},
  193: function() { foo += 74;},
  194: function() { foo += 193;},
  195: function() { foo += 160;},
  196: function() { foo += 67;},
  197: function() { foo += 224;},
  198: function() { foo += 70;},
  199: function() { foo += 132;}
  };
  
  var doSwitch = function() {
  switch(curTest) {
  case 0:
  foo += 247;break;
  case 1:
  foo += 100;break;
  case 2:
  foo += 227;break;
  case 3:
  foo += 49;break;
  case 4:
  foo += 63;break;
  case 5:
  foo += 0;break;
  case 6:
  foo += 189;break;
  case 7:
  foo += 180;break;
  case 8:
  foo += 216;break;
  case 9:
  foo += 196;break;
  case 10:
  foo += 214;break;
  case 11:
  foo += 13;break;
  case 12:
  foo += 233;break;
  case 13:
  foo += 162;break;
  case 14:
  foo += 137;break;
  case 15:
  foo += 109;break;
  case 16:
  foo += 184;break;
  case 17:
  foo += 46;break;
  case 18:
  foo += 51;break;
  case 19:
  foo += 57;break;
  case 20:
  foo += 166;break;
  case 21:
  foo += 184;break;
  case 22:
  foo += 174;break;
  case 23:
  foo += 122;break;
  case 24:
  foo += 13;break;
  case 25:
  foo += 22;break;
  case 26:
  foo += 226;break;
  case 27:
  foo += 182;break;
  case 28:
  foo += 22;break;
  case 29:
  foo += 112;break;
  case 30:
  foo += 241;break;
  case 31:
  foo += 17;break;
  case 32:
  foo += 140;break;
  case 33:
  foo += 139;break;
  case 34:
  foo += 92;break;
  case 35:
  foo += 190;break;
  case 36:
  foo += 95;break;
  case 37:
  foo += 12;break;
  case 38:
  foo += 227;break;
  case 39:
  foo += 123;break;
  case 40:
  foo += 131;break;
  case 41:
  foo += 210;break;
  case 42:
  foo += 178;break;
  case 43:
  foo += 193;break;
  case 44:
  foo += 197;break;
  case 45:
  foo += 62;break;
  case 46:
  foo += 202;break;
  case 47:
  foo += 168;break;
  case 48:
  foo += 139;break;
  case 49:
  foo += 211;break;
  case 50:
  foo += 42;break;
  case 51:
  foo += 174;break;
  case 52:
  foo += 36;break;
  case 53:
  foo += 248;break;
  case 54:
  foo += 80;break;
  case 55:
  foo += 177;break;
  case 56:
  foo += 7;break;
  case 57:
  foo += 84;break;
  case 58:
  foo += 40;break;
  case 59:
  foo += 70;break;
  case 60:
  foo += 248;break;
  case 61:
  foo += 36;break;
  case 62:
  foo += 48;break;
  case 63:
  foo += 157;break;
  case 64:
  foo += 163;break;
  case 65:
  foo += 119;break;
  case 66:
  foo += 220;break;
  case 67:
  foo += 105;break;
  case 68:
  foo += 181;break;
  case 69:
  foo += 90;break;
  case 70:
  foo += 75;break;
  case 71:
  foo += 23;break;
  case 72:
  foo += 120;break;
  case 73:
  foo += 98;break;
  case 74:
  foo += 60;break;
  case 75:
  foo += 230;break;
  case 76:
  foo += 164;break;
  case 77:
  foo += 190;break;
  case 78:
  foo += 119;break;
  case 79:
  foo += 58;break;
  case 80:
  foo += 156;break;
  case 81:
  foo += 152;break;
  case 82:
  foo += 143;break;
  case 83:
  foo += 114;break;
  case 84:
  foo += 127;break;
  case 85:
  foo += 32;break;
  case 86:
  foo += 161;break;
  case 87:
  foo += 157;break;
  case 88:
  foo += 209;break;
  case 89:
  foo += 75;break;
  case 90:
  foo += 17;break;
  case 91:
  foo += 82;break;
  case 92:
  foo += 86;break;
  case 93:
  foo += 137;break;
  case 94:
  foo += 143;break;
  case 95:
  foo += 72;break;
  case 96:
  foo += 172;break;
  case 97:
  foo += 69;break;
  case 98:
  foo += 10;break;
  case 99:
  foo += 62;break;
  case 100:
  foo += 249;break;
  case 101:
  foo += 110;break;
  case 102:
  foo += 78;break;
  case 103:
  foo += 44;break;
  case 104:
  foo += 224;break;
  case 105:
  foo += 217;break;
  case 106:
  foo += 185;break;
  case 107:
  foo += 185;break;
  case 108:
  foo += 221;break;
  case 109:
  foo += 178;break;
  case 110:
  foo += 112;break;
  case 111:
  foo += 156;break;
  case 112:
  foo += 154;break;
  case 113:
  foo += 100;break;
  case 114:
  foo += 239;break;
  case 115:
  foo += 4;break;
  case 116:
  foo += 1;break;
  case 117:
  foo += 114;break;
  case 118:
  foo += 183;break;
  case 119:
  foo += 143;break;
  case 120:
  foo += 43;break;
  case 121:
  foo += 239;break;
  case 122:
  foo += 227;break;
  case 123:
  foo += 247;break;
  case 124:
  foo += 121;break;
  case 125:
  foo += 29;break;
  case 126:
  foo += 236;break;
  case 127:
  foo += 108;break;
  case 128:
  foo += 37;break;
  case 129:
  foo += 133;break;
  case 130:
  foo += 187;break;
  case 131:
  foo += 134;break;
  case 132:
  foo += 247;break;
  case 133:
  foo += 92;break;
  case 134:
  foo += 45;break;
  case 135:
  foo += 46;break;
  case 136:
  foo += 110;break;
  case 137:
  foo += 54;break;
  case 138:
  foo += 90;break;
  case 139:
  foo += 23;break;
  case 140:
  foo += 74;break;
  case 141:
  foo += 99;break;
  case 142:
  foo += 217;break;
  case 143:
  foo += 197;break;
  case 144:
  foo += 12;break;
  case 145:
  foo += 120;break;
  case 146:
  foo += 16;break;
  case 147:
  foo += 129;break;
  case 148:
  foo += 240;break;
  case 149:
  foo += 158;break;
  case 150:
  foo += 170;break;
  case 151:
  foo += 107;break;
  case 152:
  foo += 89;break;
  case 153:
  foo += 102;break;
  case 154:
  foo += 97;break;
  case 155:
  foo += 11;break;
  case 156:
  foo += 139;break;
  case 157:
  foo += 179;break;
  case 158:
  foo += 126;break;
  case 159:
  foo += 198;break;
  case 160:
  foo += 196;break;
  case 161:
  foo += 116;break;
  case 162:
  foo += 104;break;
  case 163:
  foo += 124;break;
  case 164:
  foo += 147;break;
  case 165:
  foo += 125;break;
  case 166:
  foo += 165;break;
  case 167:
  foo += 112;break;
  case 168:
  foo += 100;break;
  case 169:
  foo += 111;break;
  case 170:
  foo += 81;break;
  case 171:
  foo += 154;break;
  case 172:
  foo += 0;break;
  case 173:
  foo += 237;break;
  case 174:
  foo += 221;break;
  case 175:
  foo += 74;break;
  case 176:
  foo += 159;break;
  case 177:
  foo += 211;break;
  case 178:
  foo += 187;break;
  case 179:
  foo += 121;break;
  case 180:
  foo += 159;break;
  case 181:
  foo += 110;break;
  case 182:
  foo += 159;break;
  case 183:
  foo += 106;break;
  case 184:
  foo += 137;break;
  case 185:
  foo += 23;break;
  case 186:
  foo += 127;break;
  case 187:
  foo += 19;break;
  case 188:
  foo += 35;break;
  case 189:
  foo += 103;break;
  case 190:
  foo += 143;break;
  case 191:
  foo += 213;break;
  case 192:
  foo += 0;break;
  case 193:
  foo += 178;break;
  case 194:
  foo += 178;break;
  case 195:
  foo += 141;break;
  case 196:
  foo += 174;break;
  case 197:
  foo += 94;break;
  case 198:
  foo += 0;break;
  case 199:
  foo += 8;break;
  };
  if(foo > 1000) {window.strthing=foo;foo=0;} /* just to make sure we don't get optimized away */
  };
  
  var doHash = function() {
     actions[curTest]();
     if(foo > 1000) {window.strthing=foo;foo=0;} /* just to make sure we don't get optimized away */
  };

Test runner

Ready to run.

Testing in
TestOps/sec
Switch
curTest ++;
if(curTest >= 200) curTest = 0;
doSwitch();
ready
Hash
curTest ++;
if(curTest >= 200) curTest = 0;
doHash();
ready

Revisions

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