Run details:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36
Chrome Mobile 126
Android
Mobile
6 months ago
Test name Executions per second
Array_filter_method 851703.6 Ops/sec
classic_for_loop_filter 648429.1 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);
      }
    }