Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
map includes vs some
(version: 0)
performance comparison of ways to find if an array contains a value
Comparing performance of:
map includes vs some
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var array = [{ foo: 'banana' }, { foo: 'sausage' }, { foo: 'jesus' }]
Tests:
map includes
array.map(x => x.foo).includes('sausage')
some
array.some(v => v.foo === 'sausage')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
map includes
some
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
map includes
52991508.0 Ops/sec
some
101064960.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark and its results. **Benchmark Purpose** The benchmark measures the performance difference between two ways of finding if an array contains a value: using `array.map()` with the `.includes()` method, and using the `some()` method directly. The test case creates an array with three objects and uses these methods to search for the presence of the string `'sausage'` in it. **Options Compared** There are two main options being compared: 1. **map includes**: This approach uses `array.map()` to create a new array with the same elements, and then checks if the resulting array contains the target value using `.includes()`. 2. **some**: This approach uses the `some()` method directly on the original array to check if any element matches the condition. **Pros and Cons** * **map includes**: + Pros: Can be more intuitive for developers who are familiar with `map()` and want to ensure that all elements match. + Cons: Creates a new array, which can lead to increased memory usage and slower performance for large datasets. + Additional overhead: The creation of the new array using `map()` adds extra work for the engine. * **some**: + Pros: More efficient in terms of memory usage, as only one iteration is required through the elements. + Cons: Requires a good understanding of how `some()` works and can be less intuitive for developers who are not familiar with it. **Library Usage** The benchmark uses the `lodash` library, which provides the `.includes()` method. The HTML preparation code includes a script tag that loads the `lodash.min.js` file from a CDN. **Special JS Features/Syntax** There is no special JavaScript feature or syntax used in this benchmark. **Other Alternatives** For comparison, other methods to check if an array contains a value could include: * Using `Array.prototype.indexOf()` or `Array.prototype.includes()` * Using a for loop with `if` statements * Using the `every()` method (which is the opposite of `some()`) These alternatives would likely produce different results and may have their own trade-offs in terms of performance, memory usage, and readability.
Related benchmarks:
array indexOf vs includes vs some aaa
array indexOf vs includes vs some 4 elements
array.indexOf vs array.includes vs array.some vs equality
array indexOf vs includes vs some vs for loop
Comments
Confirm delete:
Do you really want to delete benchmark?