Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
Chrome 79
Mac OS X 10.14.6
Desktop
4 years ago
Test name Executions per second
Object literal 18094684.0 Ops/sec
Switch 17618190.0 Ops/sec
Script Preparation code:
AخA
 
var brands = [
"Mastercard",
"Visa",
"AmericanExpress",
"DinersClub",
"Discover",
"JCB",
"UnionPay"
]
var brand = brands[Math.floor(Math.random() * 7)];
Tests:
  • Object literal

     
    var map = {
    Mastercard:"Mastercard",
    Visa:"Visa",
    AmericanExpress:"American Express",
    DinersClub: "Diners Club",
    Discover: "Discover",
    JCB: "JCB",
    UnionPay:"UnionPay",
    }
    map[brand]
  • Switch

     
      switch (brand) {
        case "Mastercard":
          return "Mastercard";
        case "Visa":
          return "Visa";
        case "American Express":
          return "AmericanExpress";
        case "Diners Club":
          return "DinersClub";
        case "Discover":
          return "Discover";
        case "JCB":
          return "Jcb";
        case "UnionPay":
          return "UnionPay";
        default:
          return "UnknownCard";
      }