Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Filter vs Find vs Some
(version: 0)
Bench
Comparing performance of:
Filter vs Find vs Some
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var data = [] for (let i = 0; i < 5000; ++i) data.push({ username: 'toto' }) data.push({ username: 'titi' }) for (let i = 0; i < 2500; ++i) data.push({ username: 'toto' })
Tests:
Filter
data.filter(e => e.username === 'titi')
Find
data.find(e => e.username === 'titi')
Some
data.some(e => e.username === 'titi')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Filter
Find
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Filter
88504.7 Ops/sec
Find
217470.8 Ops/sec
Some
213987.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided benchmark is designed to compare the performance of three different methods for filtering or searching an array in JavaScript: `filter()`, `find()`, and `some()`. **Script Preparation Code** The script preparation code generates an array `data` with 7,500 elements, consisting of two types of objects: one with a `username` property set to `'toto'` (pushed 5,000 times) and another with a `username` property set to `'titi'` (pushed 2,500 times). **Benchmark Definition JSON** The benchmark definition JSON defines three individual test cases: 1. **Filter**: `data.filter(e => e.username === 'titi')` 2. **Find**: `data.find(e => e.username === 'titi')` 3. **Some**: `data.some(e => e.username === 'titi')` **Performance Comparison** The benchmark compares the performance of each method on the generated dataset. The results are reported in terms of executions per second (ExecutionsPerSecond) for each browser and device platform. **Method Comparison** Here's a brief overview of each method and their pros and cons: 1. **Filter()** * Pros: + Returns an array with elements that pass the test. + Allows for more control over filtering conditions. * Cons: + Can be slower than `find()` or `some()` because it creates a new array. 2. **Find()** * Pros: + Faster than `filter()` since it returns the first matching element directly. + Returns an object (not an array) if found, which can be useful for caching purposes. * Cons: + Throws an error if no elements are found. 3. **Some()** * Pros: + Faster than `filter()` since it returns as soon as the first matching element is found. * Cons: + Returns a boolean value (`true` or `false`) instead of the actual matching element. **Library and Special JavaScript Features** None of the methods rely on external libraries, but some specific JavaScript features are used: 1. **Arrow functions**: Used in all three methods to define concise, lambda-like functions. 2. **Template literals**: Used in the script preparation code to create string literals with placeholders for dynamic values. **Other Alternatives** If you need more control over filtering or want to avoid returning an array, consider using other methods: 1. **Every()**: Similar to `filter()`, but returns a boolean value indicating whether all elements pass the test. 2. **forEach()`: Executes a callback function on each element in the array without modifying the original data. Keep in mind that these alternatives may have different performance characteristics and use cases compared to `filter()`, `find()`, and `some()`.
Related benchmarks:
Some vs Find vs Filter
some vs find low number of data
Some vs Find fedfd
Some vs Find early find
Comments
Confirm delete:
Do you really want to delete benchmark?