Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
123081230213812300812
(version: 0)
Comparing performance of:
filter vs find vs for...of
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr_userTags = ["freq/5", "lifetime_subscriptions/3+", "freq_beverages/0", "active_plans/1+", "active_beverages_plans/0", "freq_first/bronze", "freq_first_bucket/5", "current_freq_90d/13", "freq_first_5_8/freq<9", "freq_first_5-8/freq_5-8", "freq_first_5-8", "current_freq_90d/10+", "freq/5-8", "beverage/new", "aov_90d/40-45", "aov_lifetime/45-50", "has_voucher_coca", "coca_lover/>3", "clubber_lifecycle/active", "no_itau_purchases", "smart_cmp_coverage/middle", "smart_cmp_coverage_tier/middle", "drink_lover/>3", "guarana_lover/1", "user_had_vip", "months_with_club_subscriptions/4+", "used_mastercard_last_month", "is_vip", "months_with_club_orders/4", "ifood_beneficios", "completed_voucher_uses", "months_with_vip/1", "top_city/tier3_high", "smart_campaign/active", "club_profile/engajado", "cms/b"]; var arr_includeAll = ['drink_lover/>3', 'months_with_vip/1']; function randomInt(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function sort(arr, property) { return [...arr].sort((a, b) => (a[property] > b[property]) ? 1 : ((a[property] === b[property]) ? 0 : -1)); } var groups = []; var maxGroups = 550; var searchId = 210; for (let i = 0; i < maxGroups; i += 1) { groups.push({ id: i, priority: randomInt(2, 999), includeAll: ['drink_lover/>3', 'months_with_vip/1'], excludeAll: ['anything/0-5'], includeAny: [], excludeAny: [], }); } var sortedGroups = sort(groups, 'priority');
Tests:
filter
const filteredGroups = groups.filter((group) => { group.includeAll.every(tag => arr_userTags.includes(tag)); group.excludeAll.every(tag => !arr_userTags.includes(tag)); group.includeAny.some(tag => arr_userTags.includes(tag)); group.excludeAny.some(tag => !arr_userTags.includes(tag)); return group.id === searchId; }); const [group] = sort(filteredGroups, 'priority');
find
const group = sortedGroups.find((group) => { group.includeAll.every(tag => arr_userTags.includes(tag)); group.excludeAll.every(tag => !arr_userTags.includes(tag)); group.includeAny.some(tag => arr_userTags.includes(tag)); group.excludeAny.some(tag => !arr_userTags.includes(tag)); return group.id === searchId; });
for...of
let result; for (const group of sortedGroups) { group.includeAll.every(tag => arr_userTags.includes(tag)); group.excludeAll.every(tag => !arr_userTags.includes(tag)); group.includeAny.some(tag => arr_userTags.includes(tag)); group.excludeAny.some(tag => !arr_userTags.includes(tag)); if (group.id === searchId) { result = group; break; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
filter
find
for...of
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:
Lodash vs. Set Intersection vs Array intersection 3
Underscore vs native flat
flatMap count vs reduce count
testing flatMap, filter and for..of loop
Comments
Confirm delete:
Do you really want to delete benchmark?