Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Equals vs underscore vs lodash part 2
(version: 0)
Comparing performance of:
underscore vs lodash vs eq
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 = "no";
Tests:
underscore
underscore.isEqual(str1, str2);
lodash
lodash.isEqual(str1, str2);
eq
function getType(obj) { return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(); } if (["object", "array"].includes(getType(str1))) { } else { str1 === str2 }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
underscore
lodash
eq
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 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
underscore
10966451.0 Ops/sec
lodash
3640370.5 Ops/sec
eq
5403216.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided JSON represents a JavaScript microbenchmark test case on the website MeasureThat.net. The benchmark compares the execution performance of three different approaches to check if two strings are equal: `underscore.isEqual()`, `lodash.isEqual()`, and a custom implementation using a helper function `getType()`. **Options Compared** 1. **_ (Underscore)**: This is an instance of the popular JavaScript utility library Underscore.js, which provides various functional programming helpers. The test case uses `_ = _;` to make the underscore variable global, and then calls `underscore.isEqual(str1, str2);`. 2. **_ (Lodash)**: Similar to Underscore, this is an instance of Lodash, another popular JavaScript utility library. The test case uses `window.lodash = _;` to make the lodash variable global, and then calls `lodash.isEqual(str1, str2);`. Note that in this benchmark, `_ = null;` is used to "disable" the underscore variable before calling its methods. 3. **Custom Implementation**: This approach uses a custom helper function `getType(obj)` to check if an object is an array or not. If it's not an array, it simply checks for strict equality using `str1 === str2`. The test case only includes this implementation for the "eq" benchmark. **Pros and Cons of Each Approach** 1. **_ (Underscore)**: * Pros: Fast execution due to optimized native code. * Cons: External dependency on Underscore library, which may not be desirable in all scenarios. 2. **_ (Lodash)**: * Pros: Also fast execution due to optimized native code, and provides a wide range of utility functions. * Cons: Similar to Underscore, an external dependency that may not be desired. 3. **Custom Implementation**: * Pros: No external dependencies or overhead, allows for fine-grained control over the equality check logic. * Cons: May require more CPU cycles due to the custom implementation, and may not be as efficient as the native code optimizations in Underscore/Lodash. **Library Description** Both Underscore and Lodash are popular JavaScript utility libraries that provide various functional programming helpers. They are designed to simplify common tasks, such as array manipulation, string manipulation, and object manipulation. In this benchmark, both libraries are used for their `isEqual` function, which checks if two values are equal. **Special JS Feature/ Syntax** There is no special JavaScript feature or syntax mentioned in the benchmark code. The focus is on comparing different approaches to equality checking. **Other Alternatives** If you're looking for alternative implementations of string equality checks, here are a few options: 1. **Built-in String.prototype.equals()**: Some browsers and Node.js versions have implemented `String.prototype.equals()` method, which can be used to compare strings. 2. **Intl.NumberFormat.compare**: This is an internationalized comparison function that can be used to compare strings in a culturally aware manner. 3. **Simple string comparison using == or !==**: While not as efficient as the other options, simple string comparison using `==` or `!==` can still work for most cases. These alternatives may have different pros and cons compared to the benchmarked implementations.
Related benchmarks:
lodash isEmpty vs isEqual
lodash isNil vs native js
lodash toInteger vs parseInt
lodash parseint vs parseInt
lodash isNil vs === null || === undefined
Comments
Confirm delete:
Do you really want to delete benchmark?