Run details:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1.1 Mobile/15E148 Safari/604.1
Mobile Safari 17
iOS 17.1.1
Mobile
one year ago
Test name Executions per second
if 46626.6 Ops/sec
Math.min 1043.7 Ops/sec
Cached min 21867.5 Ops/sec
Script Preparation code:
AخA
 
arr = Array.from({ length: 10000 }, () => Math.random())
Tests:
  • if

     
    let v = 2;
    for (const x of arr) {
        if (x < v) v = x;
    }
    return v;
  • Math.min

     
    let v = 2;
    for (const x of arr) {
        v = Math.min(v, x);
    }
    return v;
  • Cached min

     
    const min = Math.min;
    let v = 2;
    for (const x of arr) {
        v = min(v, x);
    }
    return v;