Run details:
Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0
Firefox 133
Linux
Desktop
23 days ago
Test name Executions per second
filter 190343.5 Ops/sec
push 193901.3 Ops/sec
Script Preparation code:
AخA
 
  var array = [];
  for (var idx = 0; idx < 1000; idx++) {
    array[idx] = idx;
  }
  
  function oddNum(item) {
    return item % 2;
  }
  
  // Create a new array and push to it
  Array.prototype.pushFilter = function(condition) {
    // Create a new array and push to it
    var result = [];
    for(var i = 0, len = this.length; i < len; i++) {
      if (condition(this[i], i, this)) 
        result.push(this[i]);
    }
    return result;
  };
  
Tests:
  • filter

     
    var result = array.filter(oddNum);
  • push

     
    var result = array.pushFilter(oddNum);