Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
incl/set
(version: 0)
Comparing performance of:
includes vs set
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
includes
[65446, 7863, 344, 689, 7980].includes(689)
set
new Set([65446, 7863, 344, 689, 7980]).has(689)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
72967680.0 Ops/sec
set
4519441.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand what's being tested in the provided benchmark. **Benchmark Overview** The benchmark measures the performance of two JavaScript methods: `includes()` and `has()` (in the context of Sets). These methods are used for membership testing, which means they check if a specified value is present in an array or set. **Options Compared** The two options being compared are: 1. `Array.includes()`: This method checks if a specified value (`689`) is present in an array. 2. `Set.has()`: This method checks if a specified value (`689`) is present in a Set data structure. **Pros and Cons of Each Approach** * `Array.includes()`: + Pros: - Widely supported across browsers and JavaScript engines. - Simple to implement and understand. - Fast for small arrays. + Cons: - Can be slow for large arrays due to the need to iterate through each element. - May not perform well with arrays of large numbers or strings, as it uses a linear search algorithm. * `Set.has()`: This method is generally faster than `Array.includes()` for several reasons: + Pros: - Optimized for membership testing in Sets. - Can take advantage of the underlying data structure's caching and indexing. - Generally faster, especially for large datasets. + Cons: - May not be supported by older browsers or JavaScript engines. - Requires a Set object to be created, which may incur overhead. **Library Usage** In this benchmark, the `Set` library is used. A Set is a data structure that stores unique values and provides fast membership testing through methods like `has()`. The purpose of using a Set here is to compare the performance of `Set.has()` with other array-based methods. **Special JavaScript Features/Syntax** There are no special JavaScript features or syntax mentioned in this benchmark. The code snippets only use standard JavaScript methods (`includes()`, `Set.has()`) and data structures (arrays, Sets). **Other Alternatives** If you're interested in exploring alternative membership testing methods, here are a few options: * `Array.prototype.every()` with a predicate function: This method checks if all elements of an array pass a certain test. You can use it to check for membership by creating a predicate function that returns `true` if the value is present. * `Array.prototype.some()` with a predicate function: Similar to `every()`, but returns `true` as soon as any element passes the test. Keep in mind that these alternatives may have different performance characteristics and trade-offs compared to using built-in methods like `includes()` and `Set.has()`.
Related benchmarks:
Updating objects w spread
compare lodash isequal at 5 levels deep
TypedFastBitSet vs Set
Lodash isEqual test vs strict equality check
Fastest difference between multiple sets
Comments
Confirm delete:
Do you really want to delete benchmark?