switch case shorthand (v3)

Revision 3 of this benchmark created on


Description

Trying to see which is faster, a switch case statement or its shorthand.

Preparation HTML

<p>
</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
switch case
var timeStamp = function() {
    var month = 3;
    switch (month) {
    case 1:
      month = 'Jan';
      break;
    case 2:
      month = 'Feb';
      break;
    case 3:
      month = 'Mar';
      break;
    case 4:
      month = 'Apr';
      break;
    case 5:
      month = 'May';
      break;
    case 6:
      month = 'Jun';
      break;
    case 7:
      month = 'Jul';
      break;
    case 8:
      month = 'Aug';
      break;
    case 9:
      month = 'Sep';
      break;
    case 10:
      month = 'Oct';
      break;
    case 11:
      month = 'Nov';
      break;
    case 12:
      month = 'Dec';
      break;
    }
    return month;
};
$('p').append(timeStamp());
ready
shorthand
var cases = cases || {
      1: month = 'Jan',
      2: month = 'Feb',
      3: month = 'Mar',
      4: month = 'Apr',
      5: month = 'May',
      6: month = 'Jun',
      7: month = 'Jul',
      8: month = 'Aug',
      9: month = 'Sep',
      10: month = 'Oct',
      11: month = 'Nov',
      12: month = 'Dec'
    };

var timeStamp = function() {
    var month = 3;
    
    if (cases[month]) {
      cases[month]();
    }
    return month;
};
$('p').append(timeStamp());
ready

Revisions

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