Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes (with strings array)
(version: 0)
Comparing performance of:
includes vs lookup
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [ "totalScheduledPosts", "totalPublishedPosts", "totalAssetsDownloaded", "totalScheduledAds", "totalPublishedAds", "totalViewsAllPosts", "totalLikesAllPosts", "totalCommentsAllPosts", "totalSharesAllPosts", "totalLinkClicksAllPosts", "totalPublishedFacebookAds", "totalFacebookImpressions", "totalFacebookReach", "totalFacebookEngagement", "totalFacebookClicks", "totalFacebookBudgetSpent", "totalPublishedGoogleAds", "totalGoogleImpressions", "totalGoogleReach", "totalGoogleClicks", "totalGoogleBudgetSpent", "totalImpressions", "totalReach", "totalEngagement", "totalLinkClicks", "spentBudget", "totalParticipants", "totalFacebookPaidAds", "totalGooglePaidAds", "totalFacebookPaidAdsBudget", "totalGooglePaidAdsBudget", "totalFacebookPaidAdsSpend", "totalGooglePaidAdsSpend", "amountCalls", "amountEmails", "totalAdBudget", "totalAdSpend", "totalAdImpressions", "facebookPostsScheduled", "facebookPostsPublished", "facebookPostsImpressions", "facebookPostsLikes", "facebookPostsComments", "facebookPostsShares", "facebookPostsClicks", "linkedinPostsScheduled", "linkedinPostsPublished", "linkedinPostsImpressions", "linkedinPostsComments", "totalInstagramPostsScheduled", "totalInstagramPostsPublished", "totalInstagramPostsImpressions", "totalInstagramPostsReach", "totalInstagramPostsEngagement", "totalInstagramPostsVideoViews", "totalPostsScheduled", "totalPostsPublished", "totalImpressions", "totalPublishedFacebookAds", "totalScheduledFacebookAds", "totalFacebookAdsImpressions", "totalFacebookAdsReach", "totalFacebookAdsEngagement", "totalFacebookAdsClicks", "totalFacebookAdsSpent", "totalFacebookAdsBudget", "totalPublishedGoogleAds", "totalScheduledGoogleAds", "totalGoogleImpressions", "totalGoogleViews", "totalGoogleClicks", "totalGoogleAdsSpent", "totalGoogleBudget", "totalFacebookPaidAds", "totalGooglePaidAds", "totalFacebookPaidAdsBudget", "totalGooglePaidAdsBudget", "totalFacebookPaidAdsSpend", "totalGooglePaidAdsSpend", "totalPublishedAds", "totalScheduledAds", "totalAdImpressions", "totalAdClicks", "totalAdSpend", "totalAdBudget", ]; var b = new Set(a)
Tests:
includes
return a.includes('totalImpressions')
lookup
return b.has('totalImpressions')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
lookup
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):
Let's break down the provided JSON data and explain what is being tested, compared, and discussed. **Benchmark Definition** The benchmark definition represents a JavaScript function that checks if a specific string (`"totalImpressions"`) exists in two different arrays: 1. `a`: an array of strings 2. A set created from `a`, denoted as `b`. The goal is to compare the performance of these two approaches: using `array.includes()` and using a `Set` lookup (`set.has()`). **Options Compared** Two options are compared: 1. **Array.includes()**: checks if a specific value exists in an array 2. **Set lookup (`set.has()`)**: checks if a specific value exists in a set **Pros and Cons of Each Approach** **Array.includes():** Pros: * Widely supported and implemented in most browsers * Can be used with arrays of various data types, not just strings * Often faster than sets for large datasets Cons: * Has to iterate over the array to find the match * Can be slower for very large arrays or sets **Set lookup (`set.has()`):** Pros: * Fast lookups, as sets use hash tables internally * Efficient for large datasets, as it only checks existence and doesn't require iteration * Often faster than `array.includes()` for large datasets Cons: * Requires a set data structure to be created beforehand * May not be supported in older browsers or environments that don't support sets **Library Used** The `Set` data structure is used, which is a built-in JavaScript object that stores unique values. It provides an efficient way to check if a value exists in the set using the `has()` method. **Special JS Feature/Syntax** None mentioned explicitly, but it's worth noting that both `array.includes()` and `set.has()` use a concept called "iteration" under the hood, which can be optimized or sped up using techniques like parallelization or caching. However, these optimizations are not directly related to the syntax itself. **Other Alternatives** If you need to compare performance with other data structures, such as: * **Objects**: You could create an object with a specific value and check if it exists in the array using `in` operator or `Object.prototype.hasOwnProperty.call()`. However, this would be slower than sets for large datasets. * **Maps**: Similar to sets, maps provide fast lookups but are designed for key-value pairs. If you need to store data that can be accessed by a unique identifier, a map might be a better choice. Keep in mind that the performance difference between these approaches may vary depending on the specific use case and dataset size.
Related benchmarks:
Array.Includes vs a few strict equals
Array vs Set inclusion - 2
set.has vs. array.includes - including extra code for more fair comparison as typically you will have an array and not a set
set.has vs. array.includes 1e5
Array vs Set inclusion - 4
Comments
Confirm delete:
Do you really want to delete benchmark?