Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array.includes vs. set.has on the fly
(version: 0)
Comparing performance of:
includes vs lookup
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
Tests:
includes
return a.includes(9)
lookup
return new Set(a).has(9)
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:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
2943542.2 Ops/sec
lookup
709635.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. The provided JSON represents a benchmark test that compares the performance of two approaches: `includes` and `set.has`. The purpose of this benchmark is to determine which approach is faster for searching an element within an array on the fly. **Options Compared:** 1. **Array.includes**: This method searches for the specified value (`9`) in the provided array (`a`). It returns a boolean indicating whether the value is present. 2. **Set.has**: This method takes an iterable (in this case, an array `a` converted to a Set) and checks if a specific value (`9`) exists within it. It returns a boolean indicating whether the value is present. **Pros and Cons of Each Approach:** * **Array.includes**: * Pros: * Widely supported across browsers. * Easy to use. * Cons: * May not be as efficient for very large arrays due to its linear search algorithm. * **Set.has**: * Pros: * More efficient than `Array.includes` for large datasets because Set operations are optimized under the hood. * Can provide better performance for certain use cases. * Cons: * Requires converting the array to a Set, which can introduce additional overhead. **Library:** * In this benchmark, no specific library is required beyond the standard JavaScript methods (`includes` and `Set.has`). However, if you were to add additional functionality or optimize performance further, you might consider using libraries like [fast-sets](https://github.com/bjornheilman/fast-set), which provide optimized Set operations. **Special JS Feature/Syntax:** * The benchmark uses standard JavaScript features and syntax without any special or experimental features. However, it's essential to note that some JavaScript engines might implement or optimize certain methods differently depending on their implementation details. **Other Alternatives:** * If you want to explore other performance comparison options for array searches, consider benchmarks like [Google's V8 Benchmark Suite](https://v8.dev benchmark_suite), which provides a range of microbenchmarks covering various JavaScript performance scenarios. * Another alternative is using the [jsperf](http://jsperf.com/) benchmarking tool, which has been replaced by newer alternatives but remains an interesting piece of history in the context of web performance testing. In summary, this benchmark test compares the efficiency of `Array.includes` and `Set.has` methods for searching elements within arrays on the fly. While both approaches have their strengths and weaknesses, Set operations are generally more efficient for large datasets due to optimized under-the-hood implementations.
Related benchmarks:
convert to set + set.has vs. array.includes
Includes (array) vs Has (Set)
Array includes vs Set.has
set.has (w/ creation) vs. array.includes
Comments
Confirm delete:
Do you really want to delete benchmark?