Tests:
  • Simple Lookup Version

    x
     
    function getLowBits(byte, numBits){
        return ((byte >> numBits << numBits) ^ byte)
    }
    let actions = {
        0x9: [{id:"note_on", hiByte0: 0x9, loByte0: '', type:"simple", getAction(bytes){return createAction(bytes, this)}}],
        0x8: [
                {id:"bank_select", hiByte0: 0x9, loByte0: '', secondary:[0x00, 0x20], type:"msblsb", getAction(bytes){return createAction2(bytes, this)}},
                {id:"mod_wheel", hiByte0: 0x9, loByte0: '', secondary:[0x01, 0x21], type:"msblsb", getAction(bytes){return createAction2(bytes, this)}}
            ]
    }
    function createAction(bytes, action){
        return {id: action.id, channel: getLowBits(bytes[0], 4), type: "", note: bytes[1], volume: bytes[2]} 
        
    }
    function createAction2(bytes, action){
        if (action.type === "msblsb"){
            let i = action.secondary.indexOf(bytes[1])
            if (i!==-1){
                return {id: action.id, channel: getLowBits(bytes[0], 4), type: i=0?"msb":"lsb", value: bytes[2]} 
                // its a match! dunno if high or low
            } else {
                return null     // no match
            }
        }
        return null
    }
    let midi = [0x85, 0x21, 0x64]
    //let midi = [0x95, 0x21, 0x64]
    let hiByte = midi[0]>> 4
    let matches = actions[hiByte]
    let result
    if (matches.length > 1){
        for (let i = 0; i < matches.length; i++) {
            result = matches[i].getAction(midi);
            if (result){
                //console.log(JSON.stringify(result))        
                break;
            }
            
        }
    } else {
        result = matches[0].getAction(midi)
        //console.log(JSON.stringify(result))
    }
  • With lookup Loop

     
    function getLowBits(byte, numBits){
        return ((byte >> numBits << numBits) ^ byte)
    }
    let actions = {
        0x9: [{id:"note_on", hiByte0: 0x9, loByte0: '', type:"simple", getAction(bytes){return createAction(bytes, this)}}],
        0x8: [
                {id:"bank_select", hiByte0: 0x9, loByte0: '', secondary:[0x00, 0x20], type:"msblsb", getAction(bytes){return createAction2(bytes, this)}},
                {id:"mod_wheel", hiByte0: 0x9, loByte0: '', secondary:[0x01, 0x21], type:"msblsb", getAction(bytes){return createAction2(bytes, this)}}
            ]
    }
    function createAction(bytes, action){
        if (action.type==="simple"){
            return {id: action.id, channel: getLowBits(bytes[0], 4), type: "", note: bytes[1], volume: bytes[2]} 
        }
    }
    function createAction2(bytes, action){
        if (action.type === "msblsb"){
            let i = action.secondary.indexOf(bytes[1])
            if (i!==-1){
                return {id: action.id, channel: getLowBits(bytes[0], 4), type: i=0?"msb":"lsb", value: bytes[2]} 
                // its a match! dunno if high or low
            } else {
                return null     // no match
            }
        }
        return null
    }
    //let midi = [0x85, 0x21, 0x64]
    let midi = [0x95, 0x21, 0x64]
    let hiByte = midi[0]>> 4
    let matches = actions[hiByte]
    let result
    if (matches.length > 1){
        for (let i = 0; i < matches.length; i++) {
            result = matches[i].getAction(midi);
            if (result){
                //console.log(JSON.stringify(result))        
                break;
            }
            
        }
    } else {
        result = matches[0].getAction(midi)
        //console.log(JSON.stringify(result))
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Simple Lookup Version
    With lookup Loop

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
Chrome 84 on Windows
View result in a separate tab
Test name Executions per second
Simple Lookup Version 3936700.8 Ops/sec
With lookup Loop 4869159.0 Ops/sec