Run details:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1
Mobile Safari 17
iOS 17.5
Mobile
6 months ago
Test name Executions per second
Array_filter_method 10638439.0 Ops/sec
classic_for_loop_filter 6930122.0 Ops/sec
Script Preparation code:
AخA
 
var arr = new Array({ length: 10000 }, () => Math.floor(Math.random() * 1000));
Tests:
  • Array_filter_method

     
    var isGreaterThan500 = val => val > 500;
    var filtered = arr.filter(isGreaterThan500)
  • classic_for_loop_filter

    x
     
    var l = arr.length
    var filtered = [];
    for (var i = 0; i < l; i++) {
      var val = arr[i];
      if (val > 500) {
        filtered.push(val);
      }
    }