Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore vs Lodash: isEqual
(version: 0)
Compare Underscore vs Lodash isEqual. Which is faster?
Comparing performance of:
Underscore equal vs Lodash equal vs JSON Stringify comparison
Created:
6 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 type="text/javascript"> window.lodash = _; _ = null; </script> <script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js'></script> <script type="text/javascript"> window.underscore = _; _ = null; </script>
Script Preparation code:
var obj1 = { 0: { 1: { key: 'one' } } }; var obj1copy = { 0: { 1: { key: 'one' } } }; var obj2 = { 0: { 1: { key: 'two' } } };
Tests:
Underscore equal
underscore.isEqual(obj1, obj1copy);
Lodash equal
lodash.isEqual(obj1, obj1copy);
JSON Stringify comparison
JSON.stringify(obj1) === JSON.stringify(obj1copy)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Underscore equal
Lodash equal
JSON Stringify comparison
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Underscore equal
1087462.2 Ops/sec
Lodash equal
581696.9 Ops/sec
JSON Stringify comparison
890744.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain what's being tested in this benchmark and the pros and cons of each approach. **What's being tested:** The provided benchmark compares the performance of two JavaScript libraries, Underscore.js and Lodash.js, when used for equality checks on objects. Specifically, it tests the following scenarios: 1. `underscore.isEqual(obj1, obj1copy)` - This tests whether the `_` (Underscore.js) library's `isEqual` function is faster than a simple comparison using the `===` operator. 2. `lodash.isEqual(obj1, obj1copy)` - This tests whether the `_` (Lodash.js) library's `isEqual` function is faster than a simple comparison using the `===` operator. 3. `JSON.stringify(obj1) === JSON.stringify(obj1copy)` - This tests whether simply comparing the stringified representations of two objects is faster than using the equality functions provided by Underscore or Lodash. **Options compared:** The benchmark compares three options: * **Underscore.js**: A lightweight utility library that provides a set of functional programming helpers, including `isEqual`. * **Lodash.js**: A larger and more feature-rich utility library that builds upon Underscore.js and adds many more functions. * **Simple comparison (`===`)**: A basic approach that uses the equality operator to compare two objects. **Pros and cons:** 1. **Underscore.js**: * Pros: Lightweight, easy to use, and well-maintained. * Cons: May not be as comprehensive as Lodash.js, which can provide more functionality with a slightly larger footprint. 2. **Lodash.js**: * Pros: More comprehensive than Underscore.js, providing many additional functions that may be useful in certain scenarios. * Cons: Larger and heavierweight than Underscore.js, which can impact performance. 3. **Simple comparison (`===`)**: * Pros: Fastest approach, requiring no external libraries or dependencies. * Cons: May not handle complex object structures correctly or provide meaningful results for equality checks. **Library descriptions:** * **Underscore.js**: A lightweight utility library that provides a set of functional programming helpers. Its `isEqual` function compares two values and returns a boolean indicating whether they are equal. In the benchmark, Underscore.js is used to compare `obj1` with its copy (`obj1copy`) using the `_`.isEqual()` method. * **Lodash.js**: A larger utility library that builds upon Underscore.js and adds many more functions. Its `isEqual` function also compares two values and returns a boolean indicating whether they are equal. In the benchmark, Lodash.js is used to compare `obj1` with its copy (`obj1copy`) using the `_`.isEqual()` method. **Special JS features or syntax:** None mentioned in this benchmark. However, it's worth noting that some JavaScript features like async/await, Promises, and classes are not explicitly mentioned either, suggesting they may be skipped or not relevant to this specific benchmark. **Alternatives:** For similar benchmarks, you might consider comparing other libraries or approaches for equality checks, such as: * **Other utility libraries**: Other libraries like Moment.js (for date comparisons), Immutable.js (for immutable data structures), or Liskov's "Equality" functions from TypeScript. * **Native JavaScript alternatives**: Using built-in JavaScript methods, such as `===` and `!==`, in combination with JSON.stringify() for object comparison. Keep in mind that the performance differences between these approaches can be significant, so it's essential to choose the right approach depending on your specific use case.
Related benchmarks:
lodash isEmpty vs isEqual
_.isEmpty() vs Object.keys().length 3 properties
isEmpty vs Object.keys
_.isEmpty() vs Object.keys().length populated objects
Object.values() vs Object.keys().length small populated objects
Comments
Confirm delete:
Do you really want to delete benchmark?