Run details:
Mozilla/5.0 (Linux; Android 11; SM-N975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Mobile Safari/537.36
Chrome Mobile 93
Android
Mobile
3 years ago
Test name Executions per second
Filter 2218176.5 Ops/sec
For 261977.4 Ops/sec
For 2 270132.2 Ops/sec
For in 299258.2 Ops/sec
Script Preparation code:
AخA
 
var arr = [1,2,3,4,null,5,6,"7",8,{a:2},0], farr=[], i,len;
Tests:
  • Filter

    x
     
    farr= arr.filter(function(item) { 
      return (item>4); 
    });
  • For

     
    farr = [];
    for (i=0,len=arr.length;i<len;i++) {
      if (arr[i]<5) continue;
      farr.push(arr[i]);
    }
  • For 2

     
    farr = [];
    for(i=0,len=arr.length;i<len;i++) {
      if (arr[i]>4) farr.push(arr[i]);
    }
  • For in

     
    farr = [];
    for(i in arr) {
      if (arr[i]>4) farr.push(arr[i]);
    }