Tests:
  • Iterate through array once

    x
     
    const operation = [ 
        {
            "op": "replace", 
            "path": "/author/reference", 
            "value": "chewy"
        },
        {
            "op": "replace",
            "path": "/status",
            "value": "completed"
        },
        {
            "op": "replace",
            "path": "/subject/reference",
            "value": "foobar"
        }
    ];
    let statusOperation = null;
    let foundItemOperations = null;
    for (var i = 0, len = operation.length; i < len; i++) {
      operation[i].path === '/status' ? statusOperation = operation[i] : null;
      operation[i].path.indexOf('item') !== -1 ? foundItemOperations = true : null;
    }
  • Iterate through array twice

     
    const operation = [ 
        {
            "op": "replace", 
            "path": "/author/reference", 
            "value": "chewy"
        },
        {
            "op": "replace",
            "path": "/status",
            "value": "completed"
        },
        {
            "op": "replace",
            "path": "/subject/reference",
            "value": "foobar"
        }
    ];
    const statusOperation =
      operation.find(op => op.path === '/status');
    const foundItemOperations = operation.some((op) => {
      return op.path.indexOf('item') !== -1;
    });
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Iterate through array once
    Iterate through array twice

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
Chrome 78 on Mac OS X 10.14.6
View result in a separate tab
Test name Executions per second
Iterate through array once 60190328.0 Ops/sec
Iterate through array twice 15612639.0 Ops/sec