Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forEach vs filter nvmnghia 1812
(version: 3)
Comparing performance of:
filter vs forEach
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var statuses = ["active", "inactive", "nvmnghia", "bienpm"]; var data = Array.from({ length: 1_000 }, () => ({ status: statuses[Math.floor(Math.random() * statuses.length)], }));
Tests:
filter
const active = data.filter((item) => item.status === "active"); const inactive = data.filter((item) => item.status === "inactive"); const nvmnghia = data.filter((item) => item.status === "nvmnghia"); const bienpm = data.filter((item) => item.status === "bienpm"); return { active, inactive, nvmnghia, bienpm };
forEach
const active = []; const inactive = []; const nvmnghia = []; const bienpm = []; data.forEach((item) => { if (item.status === "active") active.push(item); else if (item.status === "inactive") inactive.push(item); else if (item.status === "nvmnghia") nvmnghia.push(item); else if (item.status === "bienpm") bienpm.push(item); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
filter
forEach
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
filter
48437.8 Ops/sec
forEach
66977.4 Ops/sec
Related benchmarks:
Array_Filter_VS_loop
filter vs object, massive data
String process
filter by indices
filter by indices big
Some, Filter, indexOf
Some, Filter, indexOf.
Set vs checked array add
Filter + ForEach vs ForEach with If
Comments
Confirm delete:
Do you really want to delete benchmark?