Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore vs Lodash: isEqual 5
(version: 0)
Compare Underscore vs Lodash isEqual. Which is faster?
Comparing performance of:
Vanilla vs isequal test vs var laa vs lodash vs underscore
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script> <script type="text/javascript"> window.lodash = _; _ = null; </script> <script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.2/underscore-min.js'></script> <script type="text/javascript"> window.underscore = _; _ = null; </script>
Script Preparation code:
var str1 = "awesome"; var str2 = "sauce"; function getType(obj) { return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(); } function isEqual(left, right) { function areArraysEqual() { if (left.length !== right.length) { return false; } // Check each item in the array for (let i = 0; i < left.length; i++) { if (!isEqual(left[i], right[i])) { return false; } } return true; } function areObjectsEqual() { if (Object.keys(left).length !== Object.keys(right).length) { return false; } // Check each item in the object for (let key in left) { if (Object.prototype.hasOwnProperty.call(left, key)) { if (!isEqual(left[key], right[key])) { return false; } } } return true; } function areFunctionsEqual() { return left.toString() === right.toString(); } function arePrimativesEqual() { return left === right; } let type = getType(left); if (type !== getType(right)) { return false; } if (type === "array") { return areArraysEqual(); } if (type === "object") { return areObjectsEqual(); } if (type === "function") { return areFunctionsEqual(); } return arePrimativesEqual(); }
Tests:
Vanilla
str1 === str2
isequal test
isEqual(str1, str2)
var laa
str1 == str2
lodash
lodash.isEqual(str1, str2);
underscore
underscore.isEqual(str1, str2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Vanilla
isequal test
var laa
lodash
underscore
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested, compared, and their pros/cons. **Benchmark Definition** The benchmark compares the equality checking functions of two popular JavaScript libraries: Underscore.js (Lodash) and Vanilla JavaScript. The test cases use three different approaches to check for equality: 1. `str1 === str2` (Vanilla) 2. `isEqual(str1, str2)` (Underscore's isEqual function) 3. `lodash.isEqual(str1, str2)` (Lodash's isEqual function) **Script Preparation Code** The script preparation code defines a utility function `getType(obj)` to determine the type of an object using `Object.prototype.toString.call(obj)`. This is done to differentiate between arrays, objects, functions, and primitive values. **Test Cases** Each test case uses a different string (`str1` or `str2`) to check for equality. The test cases are: 1. Vanilla: `str1 === str2` 2. Underscore's isEqual: `isEqual(str1, str2)` 3. Lodash's isEqual: `lodash.isEqual(str1, str2)` **Pros and Cons of Each Approach** 1. **Vanilla**: This approach is the most straightforward and efficient way to check for equality. However, it relies on the browser's implementation of strict equality (`===`) which may behave differently depending on the browser. * Pros: Simple, fast, and widely supported. * Cons: May not work correctly in older browsers or with certain types of data (e.g., NaN, undefined). 2. **Underscore's isEqual**: This approach uses a more complex algorithm to check for equality, which may be slower than the vanilla approach. However, it provides more flexibility and support for different data types. * Pros: Provides more accurate results for various data types, supports NaN and undefined, and is faster than the vanilla approach. * Cons: More complex implementation, potentially slower than vanilla. 3. **Lodash's isEqual**: Similar to Underscore's isEqual, this approach provides a flexible and accurate way to check for equality. However, it also adds additional overhead due to its more complex algorithm. * Pros: Provides accurate results, supports various data types, and is widely supported by Lodash users. * Cons: More overhead compared to vanilla, potentially slower. **Other Considerations** When choosing between these approaches, consider the specific requirements of your project, such as: * Accuracy: If you need strict equality checks, use Underscore's or Lodash's isEqual functions. For simpler comparisons, vanilla is sufficient. * Performance: Vanilla is generally faster than the other two approaches. * Browser support: Ensure that the chosen approach works across a range of browsers and versions. In summary, this benchmark compares three different approaches to checking for equality in JavaScript: vanilla, Underscore's isEqual, and Lodash's isEqual. While each approach has its pros and cons, vanilla is generally the fastest and most widely supported option, while Underscore's and Lodash's functions provide more flexibility and accuracy at a potential cost in performance.
Related benchmarks:
Lodash.isEqual vs Array.toString() Equality Comparison for Shallow Array of Strings.
Comparisons of performance for finding a value in an array
Lodash.isEqual vs JSON.stringify Equality Comparison for 1000 length array
_.isEqual vs for loop on Number Array
array.indexOf vs array.includes vs array.some vs equality
Comments
Confirm delete:
Do you really want to delete benchmark?