<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
window.foo = ['cat', 'dog', 'bird'];
window.bar = ['cat', 'dog', 'bird'];
_.isEqual(window.foo, window.bar)
_.isEqualWith(window.foo, window.bar, (a, b) => a===b)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
_.isEqual | |
_.isEqualShallow |
Test name | Executions per second |
---|---|
_.isEqual | 3558378.8 Ops/sec |
_.isEqualShallow | 6218734.0 Ops/sec |
Let's break down the benchmark and explain what is being tested.
What is being tested?
The provided JSON represents a JavaScript microbenchmark test case created using MeasureThat.net. The test aims to compare the performance of two functions: lodash.isEqual
and lodash.isEqualWith
, which are both used for equality comparisons.
Options compared
The two options being compared are:
_.isEqual
, but it allows for a custom equality comparison function to be passed as an argument.Pros and Cons
Here are some pros and cons of each approach:
Other Considerations
In general, when choosing between deep and shallow comparisons, consider the following:
Library: Lodash
Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, string trimming, and equality comparisons. In this case, the lodash
module is included in the benchmark HTML code using <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
, making its functions available to the test.
Special JS Feature or Syntax (Not applicable)
There are no special JavaScript features or syntax mentioned in this benchmark that would require additional explanation.
Alternatives
If you're interested in exploring alternative libraries for equality comparisons, some popular options include:
===
instead of a comparison function like _.isEqualWith
.Object.keys()
or Array.prototype.every()
to compare objects and arrays.Keep in mind that each alternative has its pros and cons, and the choice ultimately depends on your specific use case and performance requirements.