Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array filter vs. for loop - with for in 2
(version: 0)
This version declares i once before
Comparing performance of:
Filter vs For vs For 2 vs For in
Created:
8 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = [1,2,3,4,null,5,6,"7",8,{a:2},0], farr=[], i,len;
Tests:
Filter
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]); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Filter
For
For 2
For in
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
`Array.slice(-1)[0]` vs `Array[Array.length]`
`Array.slice(-1)[0]` vs `Array[Array.length]` for 10000 length
array.splice vs array.length
`array.slice(-1)[0]` vs `array[array.length - 1]`
Array.push(x) vs array[n]=x
Comments
Confirm delete:
Do you really want to delete benchmark?