objlit vs map
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36
Test name
Executions per second
Object literal
2025289.0 Ops/sec
Switch
2022409.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
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"; }
Open this result on MeasureThat.net