HTML Preparation code:
AخA
 
1
<!--your preparation HTML code goes here-->
Script Preparation code:
x
 
const f1 = () => {}
const f2 = () => {}
const f3 = () => {}
const f4 = () => {}
const f5 = () => {}
function getFnIf(level) {
    if (level === "info") return f1;
    else if (level === "warn") return f2;
    else if (level === "error") return f3;
    else if (level === "fatal") return f4;
    else return f5;
}
function getFnSwitch(level) {
    switch (level) {
        case "warn":
            return f1;
        case "info":
            return f2;
        case "error":
            return f3;
        case "fatal":
            return f4;
        default:
            return f5;
    }
}
const lookup = {
    'info': f1,
    'warn': f2,
    'error': f3,
    'fatal': f4
}
function getFnLookupString(level) {
    return lookup[level] || f5
}
const lookupN = {
    '1': f1,
    '2': f2,
    '3': f3,
    '4': f4
}
function getFnLookupN(level) {
    return lookupN[level] || f5
}
const arr = [f1,f2,f3,f4,f5]
function getFnLookupA(level) {
    return arr[level] || f5
}
Tests:
  • if

     
    getFnIf('info')
    getFnIf('warn')
    getFnIf('error')
    getFnIf('fatal')
    getFnIf()
  • switch

     
    getFnSwitch('info')
    getFnSwitch('warn')
    getFnSwitch('error')
    getFnSwitch('fatal')
    getFnSwitch()
  • lookup with strings

     
    getFnLookupString('info')
    getFnLookupString('warn')
    getFnLookupString('error')
    getFnLookupString('fatal')
    getFnLookupString()
  • lookup with number

     
    getFnLookupN('1')
    getFnLookupN('2')
    getFnLookupN('3')
    getFnLookupN('4')
    getFnLookupN()
  • lookup in array

     
    getFnLookupA(0)
    getFnLookupA(1)
    getFnLookupA(2)
    getFnLookupA(3)
    getFnLookupA()
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    if
    switch
    lookup with strings
    lookup with number
    lookup in array

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Chrome 132 on Linux
View result in a separate tab
Test name Executions per second
if 146164656.0 Ops/sec
switch 145137392.0 Ops/sec
lookup with strings 71823064.0 Ops/sec
lookup with number 41335268.0 Ops/sec
lookup in array 43572224.0 Ops/sec