Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Find: Native vs Underscore vs Lodash
(version: 0)
Comparing performance of:
Native vs Underscore vs Lodash
Created:
5 years ago
by:
Registered User
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 src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ] // Underscore was loaded last, so this saves an instance of underscore and resets _ to it's previous value (lodash). var _underscore = _.noConflict(); // This saves an instance of lodash and resets _ to it's previous value (undefined). var _lodash = _.noConflict();
Tests:
Native
users.find(function (o) { return o.age < 40; })
Underscore
_underscore.find(users, function (o) { return o.age < 40; })
Lodash
_lodash.find(users, function (o) { return o.age < 40; })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native
Underscore
Lodash
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/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
25432164.0 Ops/sec
Underscore
9933571.0 Ops/sec
Lodash
8451802.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the provided benchmark and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Overview** The test measures the performance of three different ways to find an element in an array using the `find` method: 1. Native JavaScript (`Native`) 2. Underscore.js (a utility library for functional programming) (`Underscore`) 3. Lodash (another popular utility library with a broader range of functions) (`Lodash`) **Benchmark Preparation Code** The script preparation code loads both Underscore and Lodash, but not in the same instance as native JavaScript. This is done to avoid potential conflicts between libraries. **Html Preparation Code** The HTML includes scripts for both Lodash and Underscore, which will be loaded before running the benchmark tests. **Individual Test Cases** Each test case measures a specific scenario: 1. `Native`: Finds an element in the `users` array where the age is less than 40 using only native JavaScript. 2. `_underscore.find(users, ...)` (Underscore): Uses Underscore's `find` method to achieve the same result as above. 3. `_lodash.find(users, ...)` (Lodash): Uses Lodash's `find` method with a similar syntax. **Performance Comparison** The benchmark measures the performance of each test case by executing each scenario multiple times and measuring the execution time per second. The results are: * Native: 25,432,164 executions/second * Underscore: 9,933,571 executions/second (about 38% slower than native) * Lodash: 8,451,802 executions/second (about 33% slower than native) **Pros and Cons of Each Approach** 1. **Native JavaScript**: * Pros: + Lightweight and optimized for performance. + Easy to use and understand. * Cons: + May not be as efficient for complex data processing or large datasets. 2. **Underscore.js**: * Pros: + Provides a concise and readable syntax for functional programming. + Can simplify code in some cases. * Cons: + May introduce additional overhead due to the library itself. + Can lead to slower performance compared to native JavaScript. 3. **Lodash**: * Pros: + Offers a broader range of functions and utilities for data manipulation. + Can simplify code in some cases. * Cons: + May introduce additional overhead due to the library itself. + Can lead to slower performance compared to native JavaScript. **Other Considerations** When choosing between these approaches, consider the following factors: * Performance requirements: If you need high-performance data processing, native JavaScript might be a better choice. For more complex or larger datasets, Lodash's additional functions might be beneficial. * Code readability and maintainability: Underscore.js and Lodash can simplify code in some cases, making it easier to read and understand. However, this comes at the cost of potential performance overhead. **Alternatives** Other alternatives for functional programming and data manipulation include: * Ramda (another popular utility library with a different syntax) * Moment.js (for date and time manipulation) * jQuery (a more comprehensive library for DOM manipulation and event handling) Keep in mind that this benchmark is specific to the `find` method, and performance differences may vary depending on the specific use case or dataset.
Related benchmarks:
lodash find vs native find by id
Array find vs lodash _.find
native find vs lodash _.find equal
native find() vs lodash _.find() vs native some()
native find vs lodash _.find for objects equality
Comments
Confirm delete:
Do you really want to delete benchmark?