Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Perf _.findWhere vs Native
(version: 0)
Comparing performance of:
_.findWhere vs Native
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/underscore@1.13.1/underscore-umd-min.js"></script>
Script Preparation code:
function myFindWhere(array, criteria) { return array.find(item => Object.keys(criteria).every(key => item[key] === criteria[key])) }
Tests:
_.findWhere
const array = [{"a":0, "b":1}, {"a":1}, {"b":1}]; const criteria = {"a":0}; _.findWhere(array, criteria);
Native
const array = [{"a":0, "b":1}, {"a":1}, {"b":1}]; const criteria = {"a":0}; myFindWhere(array, criteria);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.findWhere
Native
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
_.findWhere
12193585.0 Ops/sec
Native
32559104.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain what's being tested in the provided JSON, describe the options being compared, their pros and cons, and other considerations. **What's being tested:** MeasureThat.net is testing two different implementations of the `findWhere` function: one implemented using native JavaScript (`myFindWhere`) and another implemented using the popular JavaScript library Underscore.js (`_.findWhere`). The test case consists of a single array with multiple objects, each containing key-value pairs that match or don't match the given criteria. **Options being compared:** 1. **Native JavaScript (`myFindWhere`):** * Pros: + No external dependencies (no additional library overhead). + Can be optimized for specific use cases and browsers. + Direct access to browser's native functionality. * Cons: + May require more manual effort for optimization, error handling, and edge case management. + Can lead to vendor-branching issues across different browsers. 2. **Underscore.js (`_.findWhere`):** * Pros: + Provides a well-maintained and widely-used implementation with built-in optimizations. + Simplifies the development process by abstracting away low-level details. + Can be used as a drop-in replacement for similar functions in other libraries. * Cons: + Requires an external dependency, which can add overhead to the test environment. + May not provide the same level of customization or optimization as a native implementation. **Other considerations:** * The benchmark measures the number of executions per second (ExecutionsPerSecond) for each implementation, providing insight into their relative performance. * The RawUAString field contains metadata about the browser and device used to run the test, which can help identify potential biases in the results. * The DevicePlatform and OperatingSystem fields indicate that the test was run on a desktop device with Windows. **Underscore.js library:** The Underscore.js library is a popular JavaScript utility library created by Jeremy Ashkenas. It provides a set of functional programming helpers, including array manipulation functions like `findWhere`. The library is widely used in web development and has been included in MeasureThat.net's benchmark to compare the performance of native implementations against its optimized version. **Native JavaScript syntax:** The test code uses a modern JavaScript feature called arrow functions (introduced in ECMAScript 2015). An arrow function is a concise way to define small, one-time-use functions. In this case, the `myFindWhere` function uses an arrow function to simplify its implementation and improve readability. Overall, MeasureThat.net's benchmark helps software engineers understand the performance differences between native JavaScript implementations and well-established libraries like Underscore.js. This knowledge can inform design decisions and optimization strategies when working with JavaScript-based projects.
Related benchmarks:
Array.prototype.find vs Lodash find
Array.prototype.find vs Lodash find 2
Comparisons of performance for finding a value in an array
find vs lodash find
Comments
Confirm delete:
Do you really want to delete benchmark?