Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash find vs binary find
(version: 0)
Comparing performance of:
Lodash find vs Binary find
Created:
7 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>
Tests:
Lodash find
var a = ['hello', 'a', 'bc']; var b = _.find(a, item => item === 'bc');
Binary find
var a = ['hello', 'a', 'bc']; var test = function (array, id){ var startIndex = 0, stopIndex = array.length - 1, middle = Math.floor((stopIndex + startIndex)/2); while(array[middle] != id && startIndex < stopIndex){ if (id < array[middle]){ stopIndex = middle - 1; } else if (id > array[middle]){ startIndex = middle + 1; } middle = Math.floor((stopIndex + startIndex)/2); } return (array[middle] != id) ? undefined : array[middle]; } console.log(test(a, 'a'));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash find
Binary find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser/OS:
Chrome 144 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash find
28552550.0 Ops/sec
Binary find
503730.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** MeasureThat.net is testing the performance of two different approaches to find an element in an array: 1. **Lodash `find` method**: This approach uses a library called Lodash, which provides a utility function for searching arrays. In this case, the test is using the `_.find` function with a callback function that checks if each element is equal to 'bc'. 2. **Binary search algorithm**: This approach implements a binary search algorithm from scratch, without relying on any external libraries. The test uses a custom function called `test` that takes an array and a target value as input, and returns the first occurrence of the target value in the array. **Options compared** The two approaches are being compared directly: Lodash `find` vs Binary search algorithm. **Pros and Cons of each approach** **Lodash `find` method** Pros: * Simple to implement: Lodash provides a pre-existing function that can be used out-of-the-box. * Fast: Lodash is optimized for performance and is likely to be faster than implementing binary search from scratch. Cons: * External dependency: The test relies on the presence of the Lodash library, which may not be available in all environments. * Overhead: Using a library function can introduce overhead due to the need to load and initialize the library. **Binary search algorithm** Pros: * No external dependencies: This approach does not rely on any libraries or external dependencies. * Control: By implementing the binary search algorithm from scratch, developers have full control over the implementation details. Cons: * More complex to implement: Implementing a binary search algorithm from scratch requires more code and understanding of algorithms. * Potential for optimization issues: Without proper optimization, the binary search algorithm may be slower than Lodash `find`. **Other considerations** * **Language features**: The test does not use any special JavaScript features or syntax that would affect the performance comparison. However, if the test were to use modern JavaScript features like async/await or Promises, it could potentially introduce overhead and impact the performance comparison. * **Platform and hardware variations**: The test results are reported for a specific browser and device platform (Chrome 68 on Windows). It's likely that other platforms and browsers would produce different results. **Library description** The Lodash library is a utility library that provides a wide range of functions for working with arrays, objects, and other data structures. In this case, the `_.find` function is used to search an array for a specific value. **Special JS features or syntax** There are no special JavaScript features or syntax being used in this test. The code uses standard JavaScript syntax and does not rely on any advanced features like async/await or Promises.
Related benchmarks:
Array.prototype.find vs Lodash find 2
native find vs lodash _.find equal
find vs lodash find
array.find() vs. array.some() - big array version
Comments
Confirm delete:
Do you really want to delete benchmark?