Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
compare
(version: 0)
Comparing performance of:
filter vs for loop
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const users = [ { firstName: "Jane", personal: { data: ["single"], otherData: {}, }, professional: { data: ["bachelors"], otherData: {years_of_edu:[15,17]}, } }, { firstName: "John", personal: { data: ["married"], otherData: {}, }, professional: { data: ["ged"], otherData: {years_of_edu:[10,12]}, } }, { firstName: "Mike", personal: { data: ["single"], otherData: {}, }, professional: { data: ["bachelors'"], otherData: {years_of_edu:[15,17]}, } }, { firstName: "Sam", personal: { data: ["single"], otherData: [], }, professional: { data: ["ged"], otherData: {years_of_edu:[10,12]}, } }, ] const input = { personal:{ data: ["single"], extra: {} }, professional: { data: ["bachelor's"], extra: {years_of_edu:[10,12]} } }
Tests:
filter
const usersData = users.filter(function(x) { for (let item in input) { for(let items in input[item].extra) { if (input[item]?.data?.length > 0) { if (x[item]?.data.includes(...input[item]?.data) && x[item]?.otherData[items][0] >= input[item]?.extra[items][0] && x[item]?.otherData[items][1] <= input[item]?.extra[items][1] ) { return x } } } } } )
for loop
const usersData = [] for (i=0; users.length > i; i++) { for (let item in users[i]) { for(let items in users[i][item].extra) { if (input[item]?.data?.length > 0) { if (x[item]?.data.includes(...input[item]?.data) && x[item]?.otherData[items][0] >= input[item]?.extra[items][0] && x[item]?.otherData[items][1] <= input[item]?.extra[items][1] ) { usersData.push(users[i]) } } } } } )
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
filter
for loop
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!
Comments
Confirm delete:
Do you really want to delete benchmark?