Test name | Executions per second |
---|---|
Object literal | 2025288.9 Ops/sec |
Switch | 2022408.9 Ops/sec |
var brands = [
"Mastercard",
"Visa",
"AmericanExpress",
"DinersClub",
"Discover",
"JCB",
"UnionPay"
]
var brand = brands[Math.floor(Math.random() * 7)];
var map = {
Mastercard:"Mastercard",
Visa:"Visa",
AmericanExpress:"American Express",
DinersClub: "Diners Club",
Discover: "Discover",
JCB: "JCB",
UnionPay:"UnionPay",
}
map[brand]
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";
}