If vs switch (v5)

Revision 5 of this benchmark created on


Setup

const data = [...Array(1000).keys()].map(String)

Test runner

Ready to run.

Testing in
TestOps/sec
If-else
function ifelse(value) {
	if (value === "123") return "is 123"
	else if (value.includes("5")) return "has 5"
	else if (/[02468]^/.test(value)) return "is even"
	else return "something else"
}


data.forEach(ifelse)
ready
Just if
function justif(value) {
	if (value === "123") return "is 123"
	if (value.includes("5")) return "has 5"
	if (/[02468]^/.test(value)) return "is even"
	return "something else"
}


data.forEach(justif)
ready
switch-case
function switchcase(value) {
	switch(true) {
	  case (value === "123"): return "is 123"
	  case (value.includes("5")): return "has 5"
	  case (/[02468]^/.test(value)): return "is even"
	  default: return "something else"
	}
}


data.forEach(switchcase)
ready
lookup table
const table = {
    "0": "is even",
    "1": "something else",
    "2": "is even",
    "3": "something else",
    "4": "is even",
    "5": "has 5",
    "6": "is even",
    "7": "something else",
    "8": "is even",
    "9": "something else",
    "10": "is even",
    "11": "something else",
    "12": "is even",
    "13": "something else",
    "14": "is even",
    "15": "has 5",
    "16": "is even",
    "17": "something else",
    "18": "is even",
    "19": "something else",
    "20": "is even",
    "21": "something else",
    "22": "is even",
    "23": "something else",
    "24": "is even",
    "25": "has 5",
    "26": "is even",
    "27": "something else",
    "28": "is even",
    "29": "something else",
    "30": "is even",
    "31": "something else",
    "32": "is even",
    "33": "something else",
    "34": "is even",
    "35": "has 5",
    "36": "is even",
    "37": "something else",
    "38": "is even",
    "39": "something else",
    "40": "is even",
    "41": "something else",
    "42": "is even",
    "43": "something else",
    "44": "is even",
    "45": "has 5",
    "46": "is even",
    "47": "something else",
    "48": "is even",
    "49": "something else",
    "50": "is even",
    "51": "has 5",
    "52": "is even",
    "53": "has 5",
    "54": "is even",
    "55": "has 5",
    "56": "is even",
    "57": "has 5",
    "58": "is even",
    "59": "has 5",
    "60": "is even",
    "61": "something else",
    "62": "is even",
    "63": "something else",
    "64": "is even",
    "65": "has 5",
    "66": "is even",
    "67": "something else",
    "68": "is even",
    "69": "something else",
    "70": "is even",
    "71": "something else",
    "72": "is even",
    "73": "something else",
    "74": "is even",
    "75": "has 5",
    "76": "is even",
    "77": "something else",
    "78": "is even",
    "79": "something else",
    "80": "is even",
    "81": "something else",
    "82": "is even",
    "83": "something else",
    "84": "is even",
    "85": "has 5",
    "86": "is even",
    "87": "something else",
    "88": "is even",
    "89": "something else",
    "90": "is even",
    "91": "something else",
    "92": "is even",
    "93": "something else",
    "94": "is even",
    "95": "has 5",
    "96": "is even",
    "97": "something else",
    "98": "is even",
    "99": "something else",
    "100": "is even",
    "101": "something else",
    "102": "is even",
    "103": "something else",
    "104": "is even",
    "105": "has 5",
    "106": "is even",
    "107": "something else",
    "108": "is even",
    "109": "something else",
    "110": "is even",
    "111": "something else",
    "112": "is even",
    "113": "something else",
    "114": "is even",
    "115": "has 5",
    "116": "is even",
    "117": "something else",
    "118": "is even",
    "119": "something else",
    "120": "is even",
    "121": "something else",
    "122": "is even",
    "123": "is 123",
    "124": "is even",
    "125": "has 5",
    "126": "is even",
    "127": "something else",
    "128": "is even",
    "129": "something else",
    "130": "is even",
    "131": "something else",
    "132": "is even",
    "133": "something else",
    "134": "is even",
    "135": "has 5",
    "136": "is even",
    "137": "something else",
    "138": "is even",
    "139": "something else",
    "140": "is even",
    "141": "something else",
    "142": "is even",
    "143": "something else",
    "144": "is even",
    "145": "has 5",
    "146": "is even",
    "147": "something else",
    "148": "is even",
    "149": "something else",
    "150": "is even",
    "151": "has 5",
    "152": "is even",
    "153": "has 5",
    "154": "is even",
    "155": "has 5",
    "156": "is even",
    "157": "has 5",
    "158": "is even",
    "159": "has 5",
    "160": "is even",
    "161": "something else",
    "162": "is even",
    "163": "something else",
    "164": "is even",
    "165": "has 5",
    "166": "is even",
    "167": "something else",
    "168": "is even",
    "169": "something else",
    "170": "is even",
    "171": "something else",
    "172": "is even",
    "173": "something else",
    "174": "is even",
    "175": "has 5",
    "176": "is even",
    "177": "something else",
    "178": "is even",
    "179": "something else",
    "180": "is even",
    "181": "something else",
    "182": "is even",
    "183": "something else",
    "184": "is even",
    "185": "has 5",
    "186": "is even",
    "187": "something else",
    "188": "is even",
    "189": "something else",
    "190": "is even",
    "191": "something else",
    "192": "is even",
    "193": "something else",
    "194": "is even",
    "195": "has 5",
    "196": "is even",
    "197": "something else",
    "198": "is even",
    "199": "something else",
    "200": "is even",
    "201": "something else",
    "202": "is even",
    "203": "something else",
    "204": "is even",
    "205": "has 5",
    "206": "is even",
    "207": "something else",
    "208": "is even",
    "209": "something else",
    "210": "is even",
    "211": "something else",
    "212": "is even",
    "213": "something else",
    "214": "is even",
    "215": "has 5",
    "216": "is even",
    "217": "something else",
    "218": "is even",
    "219": "something else",
    "220": "is even",
    "221": "something else",
    "222": "is even",
    "223": "something else",
    "224": "is even",
    "225": "has 5",
    "226": "is even",
    "227": "something else",
    "228": "is even",
    "229": "something else",
    "230": "is even",
    "231": "something else",
    "232": "is even",
    "233": "something else",
    "234": "is even",
    "235": "has 5",
    "236": "is even",
    "237": "something else",
    "238": "is even",
    "239": "something else",
    "240": "is even",
    "241": "something else",
    "242": "is even",
    "243": "something else",
    "244": "is even",
    "245": "has 5",
    "246": "is even",
    "247": "something else",
    "248": "is even",
    "249": "something else",
    "250": "is even",
    "251": "has 5",
    "252": "is even",
    "253": "has 5",
    "254": "is even",
    "255": "has 5",
    "256": "is even",
    "257": "has 5",
    "258": "is even",
    "259": "has 5",
    "260": "is even",
    "261": "something else",
    "262": "is even",
    "263": "something else",
    "264": "is even",
    "265": "has 5",
    "266": "is even",
    "267": "something else",
    "268": "is even",
    "269": "something else",
    "270": "is even",
    "271": "something else",
    "272": "is even",
    "273": "something else",
    "274": "is even",
    "275": "has 5",
    "276": "is even",
    "277": "something else",
    "278": "is even",
    "279": "something else",
    "280": "is even",
    "281": "something else",
    "282": "is even",
    "283": "something else",
    "284": "is even",
    "285": "has 5",
    "286": "is even",
    "287": "something else",
    "288": "is even",
    "289": "something else",
    "290": "is even",
    "291": "something else",
    "292": "is even",
    "293": "something else",
    "294": "is even",
    "295": "has 5",
    "296": "is even",
    "297": "something else",
    "298": "is even",
    "299": "something else",
    "300": "is even",
    "301": "something else",
    "302": "is even",
    "303": "something else",
    "304": "is even",
    "305": "has 5",
    "306": "is even",
    "307": "something else",
    "308": "is even",
    "309": "something else",
    "310": "is even",
    "311": "something else",
    "312": "is even",
    "313": "something else",
    "314": "is even",
    "315": "has 5",
    "316": "is even",
    "317": "something else",
    "318": "is even",
    "319": "something else",
    "320": "is even",
    "321": "something else",
    "322": "is even",
    "323": "something else",
    "324": "is even",
    "325": "has 5",
    "326": "is even",
    "327": "something else",
    "328": "is even",
    "329": "something else",
    "330": "is even",
    "331": "something else",
    "332": "is even",
    "333": "something else",
    "334": "is even",
    "335": "has 5",
    "336": "is even",
    "337": "something else",
    "338": "is even",
    "339": "something else",
    "340": "is even",
    "341": "something else",
    "342": "is even",
    "343": "something else",
    "344": "is even",
    "345": "has 5",
    "346": "is even",
    "347": "something else",
    "348": "is even",
    "349": "something else",
    "350": "is even",
    "351": "has 5",
    "352": "is even",
    "353": "has 5",
    "354": "is even",
    "355": "has 5",
    "356": "is even",
    "357": "has 5",
    "358": "is even",
    "359": "has 5",
    "360": "is even",
    "361": "something else",
    "362": "is even",
    "363": "something else",
    "364": "is even",
    "365": "has 5",
    "366": "is even",
    "367": "something else",
    "368": "is even",
    "369": "something else",
    "370": "is even",
    "371": "something else",
    "372": "is even",
    "373": "something else",
    "374": "is even",
    "375": "has 5",
    "376": "is even",
    "377": "something else",
    "378": "is even",
    "379": "something else",
    "380": "is even",
    "381": "something else",
    "382": "is even",
    "383": "something else",
    "384": "is even",
    "385": "has 5",
    "386": "is even",
    "387": "something else",
    "388": "is even",
    "389": "something else",
    "390": "is even",
    "391": "something else",
    "392": "is even",
    "393": "something else",
    "394": "is even",
    "395": "has 5",
    "396": "is even",
    "397": "something else",
    "398": "is even",
    "399": "something else",
    "400": "is even",
    "401": "something else",
    "402": "is even",
    "403": "something else",
    "404": "is even",
    "405": "has 5",
    "406": "is even",
    "407": "something else",
    "408": "is even",
    "409": "something else",
    "410": "is even",
    "411": "something else",
    "412": "is even",
    "413": "something else",
    "414": "is even",
    "415": "has 5",
    "416": "is even",
    "417": "something else",
    "418": "is even",
    "419": "something else",
    "420": "is even",
    "421": "something else",
    "422": "is even",
    "423": "something else",
    "424": "is even",
    "425": "has 5",
    "426": "is even",
    "427": "something else",
    "428": "is even",
    "429": "something else",
    "430": "is even",
    "431": "something else",
    "432": "is even",
    "433": "something else",
    "434": "is even",
    "435": "has 5",
    "436": "is even",
    "437": "something else",
    "438": "is even",
    "439": "something else",
    "440": "is even",
    "441": "something else",
    "442": "is even",
    "443": "something else",
    "444": "is even",
    "445": "has 5",
    "446": "is even",
    "447": "something else",
    "448": "is even",
    "449": "something else",
    "450": "is even",
    "451": "has 5",
    "452": "is even",
    "453": "has 5",
    "454": "is even",
    "455": "has 5",
    "456": "is even",
    "457": "has 5",
    "458": "is even",
    "459": "has 5",
    "460": "is even",
    "461": "something else",
    "462": "is even",
    "463": "something else",
    "464": "is even",
    "465": "has 5",
    "466": "is even",
    "467": "something else",
    "468": "is even",
    "469": "something else",
    "470": "is even",
    "471": "something else",
    "472": "is even",
    "473": "something else",
    "474": "is even",
    "475": "has 5",
    "476": "is even",
    "477": "something else",
    "478": "is even",
    "479": "something else",
    "480": "is even",
    "481": "something else",
    "482": "is even",
    "483": "something else",
    "484": "is even",
    "485": "has 5",
    "486": "is even",
    "487": "something else",
    "488": "is even",
    "489": "something else",
    "490": "is even",
    "491": "something else",
    "492": "is even",
    "493": "something else",
    "494": "is even",
    "495": "has 5",
    "496": "is even",
    "497": "something else",
    "498": "is even",
    "499": "something else",
    "500": "is even",
    "501": "has 5",
    "502": "is even",
    "503": "has 5",
    "504": "is even",
    "505": "has 5",
    "506": "is even",
    "507": "has 5",
    "508": "is even",
    "509": "has 5",
    "510": "is even",
    "511": "has 5",
    "512": "is even",
    "513": "has 5",
    "514": "is even",
    "515": "has 5",
    "516": "is even",
    "517": "has 5",
    "518": "is even",
    "519": "has 5",
    "520": "is even",
    "521": "has 5",
    "522": "is even",
    "523": "has 5",
    "524": "is even",
    "525": "has 5",
    "526": "is even",
    "527": "has 5",
    "528": "is even",
    "529": "has 5",
    "530": "is even",
    "531": "has 5",
    "532": "is even",
    "533": "has 5",
    "534": "is even",
    "535": "has 5",
    "536": "is even",
    "537": "has 5",
    "538": "is even",
    "539": "has 5",
    "540": "is even",
    "541": "has 5",
    "542": "is even",
    "543": "has 5",
    "544": "is even",
    "545": "has 5",
    "546": "is even",
    "547": "has 5",
    "548": "is even",
    "549": "has 5",
    "550": "is even",
    "551": "has 5",
    "552": "is even",
    "553": "has 5",
    "554": "is even",
    "555": "has 5",
    "556": "is even",
    "557": "has 5",
    "558": "is even",
    "559": "has 5",
    "560": "is even",
    "561": "has 5",
    "562": "is even",
    "563": "has 5",
    "564": "is even",
    "565": "has 5",
    "566": "is even",
    "567": "has 5",
    "568": "is even",
    "569": "has 5",
    "570": "is even",
    "571": "has 5",
    "572": "is even",
    "573": "has 5",
    "574": "is even",
    "575": "has 5",
    "576": "is even",
    "577": "has 5",
    "578": "is even",
    "579": "has 5",
    "580": "is even",
    "581": "has 5",
    "582": "is even",
    "583": "has 5",
    "584": "is even",
    "585": "has 5",
    "586": "is even",
    "587": "has 5",
    "588": "is even",
    "589": "has 5",
    "590": "is even",
    "591": "has 5",
    "592": "is even",
    "593": "has 5",
    "594": "is even",
    "595": "has 5",
    "596": "is even",
    "597": "has 5",
    "598": "is even",
    "599": "has 5",
    "600": "is even",
    "601": "something else",
    "602": "is even",
    "603": "something else",
    "604": "is even",
    "605": "has 5",
    "606": "is even",
    "607": "something else",
    "608": "is even",
    "609": "something else",
    "610": "is even",
    "611": "something else",
    "612": "is even",
    "613": "something else",
    "614": "is even",
    "615": "has 5",
    "616": "is even",
    "617": "something else",
    "618": "is even",
    "619": "something else",
    "620": "is even",
    "621": "something else",
    "622": "is even",
    "623": "something else",
    "624": "is even",
    "625": "has 5",
    "626": "is even",
    "627": "something else",
    "628": "is even",
    "629": "something else",
    "630": "is even",
    "631": "something else",
    "632": "is even",
    "633": "something else",
    "634": "is even",
    "635": "has 5",
    "636": "is even",
    "637": "something else",
    "638": "is even",
    "639": "something else",
    "640": "is even",
    "641": "something else",
    "642": "is even",
    "643": "something else",
    "644": "is even",
    "645": "has 5",
    "646": "is even",
    "647": "something else",
    "648": "is even",
    "649": "something else",
    "650": "is even",
    "651": "has 5",
    "652": "is even",
    "653": "has 5",
    "654": "is even",
    "655": "has 5",
    "656": "is even",
    "657": "has 5",
    "658": "is even",
    "659": "has 5",
    "660": "is even",
    "661": "something else",
    "662": "is even",
    "663": "something else",
    "664": "is even",
    "665": "has 5",
    "666": "is even",
    "667": "something else",
    "668": "is even",
    "669": "something else",
    "670": "is even",
    "671": "something else",
    "672": "is even",
    "673": "something else",
    "674": "is even",
    "675": "has 5",
    "676": "is even",
    "677": "something else",
    "678": "is even",
    "679": "something else",
    "680": "is even",
    "681": "something else",
    "682": "is even",
    "683": "something else",
    "684": "is even",
    "685": "has 5",
    "686": "is even",
    "687": "something else",
    "688": "is even",
    "689": "something else",
    "690": "is even",
    "691": "something else",
    "692": "is even",
    "693": "something else",
    "694": "is even",
    "695": "has 5",
    "696": "is even",
    "697": "something else",
    "698": "is even",
    "699": "something else",
    "700": "is even",
    "701": "something else",
    "702": "is even",
    "703": "something else",
    "704": "is even",
    "705": "has 5",
    "706": "is even",
    "707": "something else",
    "708": "is even",
    "709": "something else",
    "710": "is even",
    "711": "something else",
    "712": "is even",
    "713": "something else",
    "714": "is even",
    "715": "has 5",
    "716": "is even",
    "717": "something else",
    "718": "is even",
    "719": "something else",
    "720": "is even",
    "721": "something else",
    "722": "is even",
    "723": "something else",
    "724": "is even",
    "725": "has 5",
    "726": "is even",
    "727": "something else",
    "728": "is even",
    "729": "something else",
    "730": "is even",
    "731": "something else",
    "732": "is even",
    "733": "something else",
    "734": "is even",
    "735": "has 5",
    "736": "is even",
    "737": "something else",
    "738": "is even",
    "739": "something else",
    "740": "is even",
    "741": "something else",
    "742": "is even",
    "743": "something else",
    "744": "is even",
    "745": "has 5",
    "746": "is even",
    "747": "something else",
    "748": "is even",
    "749": "something else",
    "750": "is even",
    "751": "has 5",
    "752": "is even",
    "753": "has 5",
    "754": "is even",
    "755": "has 5",
    "756": "is even",
    "757": "has 5",
    "758": "is even",
    "759": "has 5",
    "760": "is even",
    "761": "something else",
    "762": "is even",
    "763": "something else",
    "764": "is even",
    "765": "has 5",
    "766": "is even",
    "767": "something else",
    "768": "is even",
    "769": "something else",
    "770": "is even",
    "771": "something else",
    "772": "is even",
    "773": "something else",
    "774": "is even",
    "775": "has 5",
    "776": "is even",
    "777": "something else",
    "778": "is even",
    "779": "something else",
    "780": "is even",
    "781": "something else",
    "782": "is even",
    "783": "something else",
    "784": "is even",
    "785": "has 5",
    "786": "is even",
    "787": "something else",
    "788": "is even",
    "789": "something else",
    "790": "is even",
    "791": "something else",
    "792": "is even",
    "793": "something else",
    "794": "is even",
    "795": "has 5",
    "796": "is even",
    "797": "something else",
    "798": "is even",
    "799": "something else",
    "800": "is even",
    "801": "something else",
    "802": "is even",
    "803": "something else",
    "804": "is even",
    "805": "has 5",
    "806": "is even",
    "807": "something else",
    "808": "is even",
    "809": "something else",
    "810": "is even",
    "811": "something else",
    "812": "is even",
    "813": "something else",
    "814": "is even",
    "815": "has 5",
    "816": "is even",
    "817": "something else",
    "818": "is even",
    "819": "something else",
    "820": "is even",
    "821": "something else",
    "822": "is even",
    "823": "something else",
    "824": "is even",
    "825": "has 5",
    "826": "is even",
    "827": "something else",
    "828": "is even",
    "829": "something else",
    "830": "is even",
    "831": "something else",
    "832": "is even",
    "833": "something else",
    "834": "is even",
    "835": "has 5",
    "836": "is even",
    "837": "something else",
    "838": "is even",
    "839": "something else",
    "840": "is even",
    "841": "something else",
    "842": "is even",
    "843": "something else",
    "844": "is even",
    "845": "has 5",
    "846": "is even",
    "847": "something else",
    "848": "is even",
    "849": "something else",
    "850": "is even",
    "851": "has 5",
    "852": "is even",
    "853": "has 5",
    "854": "is even",
    "855": "has 5",
    "856": "is even",
    "857": "has 5",
    "858": "is even",
    "859": "has 5",
    "860": "is even",
    "861": "something else",
    "862": "is even",
    "863": "something else",
    "864": "is even",
    "865": "has 5",
    "866": "is even",
    "867": "something else",
    "868": "is even",
    "869": "something else",
    "870": "is even",
    "871": "something else",
    "872": "is even",
    "873": "something else",
    "874": "is even",
    "875": "has 5",
    "876": "is even",
    "877": "something else",
    "878": "is even",
    "879": "something else",
    "880": "is even",
    "881": "something else",
    "882": "is even",
    "883": "something else",
    "884": "is even",
    "885": "has 5",
    "886": "is even",
    "887": "something else",
    "888": "is even",
    "889": "something else",
    "890": "is even",
    "891": "something else",
    "892": "is even",
    "893": "something else",
    "894": "is even",
    "895": "has 5",
    "896": "is even",
    "897": "something else",
    "898": "is even",
    "899": "something else",
    "900": "is even",
    "901": "something else",
    "902": "is even",
    "903": "something else",
    "904": "is even",
    "905": "has 5",
    "906": "is even",
    "907": "something else",
    "908": "is even",
    "909": "something else",
    "910": "is even",
    "911": "something else",
    "912": "is even",
    "913": "something else",
    "914": "is even",
    "915": "has 5",
    "916": "is even",
    "917": "something else",
    "918": "is even",
    "919": "something else",
    "920": "is even",
    "921": "something else",
    "922": "is even",
    "923": "something else",
    "924": "is even",
    "925": "has 5",
    "926": "is even",
    "927": "something else",
    "928": "is even",
    "929": "something else",
    "930": "is even",
    "931": "something else",
    "932": "is even",
    "933": "something else",
    "934": "is even",
    "935": "has 5",
    "936": "is even",
    "937": "something else",
    "938": "is even",
    "939": "something else",
    "940": "is even",
    "941": "something else",
    "942": "is even",
    "943": "something else",
    "944": "is even",
    "945": "has 5",
    "946": "is even",
    "947": "something else",
    "948": "is even",
    "949": "something else",
    "950": "is even",
    "951": "has 5",
    "952": "is even",
    "953": "has 5",
    "954": "is even",
    "955": "has 5",
    "956": "is even",
    "957": "has 5",
    "958": "is even",
    "959": "has 5",
    "960": "is even",
    "961": "something else",
    "962": "is even",
    "963": "something else",
    "964": "is even",
    "965": "has 5",
    "966": "is even",
    "967": "something else",
    "968": "is even",
    "969": "something else",
    "970": "is even",
    "971": "something else",
    "972": "is even",
    "973": "something else",
    "974": "is even",
    "975": "has 5",
    "976": "is even",
    "977": "something else",
    "978": "is even",
    "979": "something else",
    "980": "is even",
    "981": "something else",
    "982": "is even",
    "983": "something else",
    "984": "is even",
    "985": "has 5",
    "986": "is even",
    "987": "something else",
    "988": "is even",
    "989": "something else",
    "990": "is even",
    "991": "something else",
    "992": "is even",
    "993": "something else",
    "994": "is even",
    "995": "has 5",
    "996": "is even",
    "997": "something else",
    "998": "is even",
    "999": "something else"
}

data.forEach(i => table[i])
ready

Revisions

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