Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Filter, for, for of, forEach
(version: 0)
Comparing performance of:
filter vs for vs for of vs forEach
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const obj = { ID: '332', ACCOMPLICES: [], ACTIVITY_DATE: "2023-03-13T00:01:35+03:00", ALLOW_CHANGE_DEADLINE: "N", ALLOW_TIME_TRACKING: "N", AUDITORS: [], CHANGED_DATE: "2023-03-13T00:01:35+03:00", CHECKLIST: [], CREATED_BY: "1", DEADLINE: "2023-03-10T19:00:00+03:00", DESCRIPTION: "", DURATION_PLAN: "0", DURATION_TYPE: "days", END_DATE_PLAN: null, GROUP_ID: null, MARK: null, MATCH_WORK_TIME: "N", PRIORITY: "1", RESPONSIBLE_ID: "1", START_DATE_PLAN: "2023-03-08T23:58:00+03:00", STATUS: "2", TASK_CONTROL: "N", TIME_ESTIMATE: null, TIME_SPENT_IN_LOGS: "0", TITLE: "switches", UF_CRM_TASK: [], UF_TASK_WEBDAV_FILES: ["n186", "n188", "n190", "n192", "n708", "n710"], } const arr = []; for (const idx of [...Array(10000).keys()]) { arr.push({ ...obj, ID: idx }) }
Tests:
filter
const obj = { ID: '332', ACCOMPLICES: [], ACTIVITY_DATE: "2023-03-13T00:01:35+03:00", ALLOW_CHANGE_DEADLINE: "N", ALLOW_TIME_TRACKING: "N", AUDITORS: [], CHANGED_DATE: "2023-03-13T00:01:35+03:00", CHECKLIST: [], CREATED_BY: "1", DEADLINE: "2023-03-10T19:00:00+03:00", DESCRIPTION: "", DURATION_PLAN: "0", DURATION_TYPE: "days", END_DATE_PLAN: null, GROUP_ID: null, MARK: null, MATCH_WORK_TIME: "N", PRIORITY: "1", RESPONSIBLE_ID: "1", START_DATE_PLAN: "2023-03-08T23:58:00+03:00", STATUS: "2", TASK_CONTROL: "N", TIME_ESTIMATE: null, TIME_SPENT_IN_LOGS: "0", TITLE: "switches", UF_CRM_TASK: [], UF_TASK_WEBDAV_FILES: ["n186", "n188", "n190", "n192", "n708", "n710"], } const arr = []; for (const idx of [...Array(10000).keys()]) { arr.push({ ...obj, ID: idx }) } const newArr = arr.filter((item) => item.ID % 2);
for
const obj = { ID: '332', ACCOMPLICES: [], ACTIVITY_DATE: "2023-03-13T00:01:35+03:00", ALLOW_CHANGE_DEADLINE: "N", ALLOW_TIME_TRACKING: "N", AUDITORS: [], CHANGED_DATE: "2023-03-13T00:01:35+03:00", CHECKLIST: [], CREATED_BY: "1", DEADLINE: "2023-03-10T19:00:00+03:00", DESCRIPTION: "", DURATION_PLAN: "0", DURATION_TYPE: "days", END_DATE_PLAN: null, GROUP_ID: null, MARK: null, MATCH_WORK_TIME: "N", PRIORITY: "1", RESPONSIBLE_ID: "1", START_DATE_PLAN: "2023-03-08T23:58:00+03:00", STATUS: "2", TASK_CONTROL: "N", TIME_ESTIMATE: null, TIME_SPENT_IN_LOGS: "0", TITLE: "switches", UF_CRM_TASK: [], UF_TASK_WEBDAV_FILES: ["n186", "n188", "n190", "n192", "n708", "n710"], } const arr = []; for (const idx of [...Array(10000).keys()]) { arr.push({ ...obj, ID: idx }) } const newArr = []; for(let i = 0; i < arr.length; i++) { if(arr[i].ID % 2){ newArr.push(arr[i]); } }
for of
const obj = { ID: '332', ACCOMPLICES: [], ACTIVITY_DATE: "2023-03-13T00:01:35+03:00", ALLOW_CHANGE_DEADLINE: "N", ALLOW_TIME_TRACKING: "N", AUDITORS: [], CHANGED_DATE: "2023-03-13T00:01:35+03:00", CHECKLIST: [], CREATED_BY: "1", DEADLINE: "2023-03-10T19:00:00+03:00", DESCRIPTION: "", DURATION_PLAN: "0", DURATION_TYPE: "days", END_DATE_PLAN: null, GROUP_ID: null, MARK: null, MATCH_WORK_TIME: "N", PRIORITY: "1", RESPONSIBLE_ID: "1", START_DATE_PLAN: "2023-03-08T23:58:00+03:00", STATUS: "2", TASK_CONTROL: "N", TIME_ESTIMATE: null, TIME_SPENT_IN_LOGS: "0", TITLE: "switches", UF_CRM_TASK: [], UF_TASK_WEBDAV_FILES: ["n186", "n188", "n190", "n192", "n708", "n710"], } const arr = []; for (const idx of [...Array(10000).keys()]) { arr.push({ ...obj, ID: idx }) } const newArr = []; for(const item of arr) { if(item.ID % 2 ) { newArr.push(item); } }
forEach
const obj = { ID: '332', ACCOMPLICES: [], ACTIVITY_DATE: "2023-03-13T00:01:35+03:00", ALLOW_CHANGE_DEADLINE: "N", ALLOW_TIME_TRACKING: "N", AUDITORS: [], CHANGED_DATE: "2023-03-13T00:01:35+03:00", CHECKLIST: [], CREATED_BY: "1", DEADLINE: "2023-03-10T19:00:00+03:00", DESCRIPTION: "", DURATION_PLAN: "0", DURATION_TYPE: "days", END_DATE_PLAN: null, GROUP_ID: null, MARK: null, MATCH_WORK_TIME: "N", PRIORITY: "1", RESPONSIBLE_ID: "1", START_DATE_PLAN: "2023-03-08T23:58:00+03:00", STATUS: "2", TASK_CONTROL: "N", TIME_ESTIMATE: null, TIME_SPENT_IN_LOGS: "0", TITLE: "switches", UF_CRM_TASK: [], UF_TASK_WEBDAV_FILES: ["n186", "n188", "n190", "n192", "n708", "n710"], } const arr = []; for (const idx of [...Array(10000).keys()]) { arr.push({ ...obj, ID: idx }) } const newArr = []; arr.forEach(el => { if(el.ID % 2){ newArr.push(el); } } );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
filter
for
for of
forEach
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!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
A benchmarking question! It appears that we have two tests: `forEach` and `for`. The latest benchmark result shows the performance of Firefox 118 on a Linux desktop, with different test cases: 1. `forEach`: 280 executions per second 2. `for`: 280 executions per second ( similar to `forEach`, but slightly lower) 3. `filter`: 244 executions per second ( significantly slower than both `forEach` and `for`) 4. `for of`: 243 executions per second ( almost identical to `forEach`, with a slight difference) Based on these results, we can conclude that: * `forEach` is the fastest among the four tests * `filter` is the slowest * `for` and `for of` are similar in performance, but slightly slower than `forEach` This suggests that `forEach` might be a more efficient iteration method for this specific use case. However, without knowing the exact implementation details or context, it's difficult to make any further conclusions.
Related benchmarks:
dsdsdsdsdsdsds
asdfasdfasdf
[MH-4355][1000]: lodash / es6 filter perf
ISO 8601 parsing
Comments
Confirm delete:
Do you really want to delete benchmark?